0% found this document useful (0 votes)
7 views

SQL_TP[1]

The document provides a detailed overview of Data Definition Language (DDL) commands in SQL, including CREATE, RENAME, ALTER, DROP, and TRUNCATE commands. It explains the purpose of DDL in managing database structures and provides syntax and examples for each command. The presentation is prepared by Group No. 6, consisting of six members.

Uploaded by

arpitgulhane123
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

SQL_TP[1]

The document provides a detailed overview of Data Definition Language (DDL) commands in SQL, including CREATE, RENAME, ALTER, DROP, and TRUNCATE commands. It explains the purpose of DDL in managing database structures and provides syntax and examples for each command. The presentation is prepared by Group No. 6, consisting of six members.

Uploaded by

arpitgulhane123
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 17

Technical

Presentation
(SQL)

DDL Commands in detail by


Group no.6
Topic
TO Explain (DDL)Data Definition
Language commands in SQL
 INTRODUCTION TO DDL
 CREATE TABLE
 RENAME TABLE
 ALTER TABLE
 DROP TABLE
 TRUNCATE TABLE
Group No.6
Group Members
• Rutuja Mane
• Minal Phale
• Arpit Gulhane
• Pranjal Karwade
• Vaishnavi Gaikwad
• Vijay Jadhav
Introduction To DDL
• Definition:
Data Definition Language (DDL) is a subset of SQL (Structured Query
Language) used to define, manage, and control the structure of a
database.

• Purpose:
DDL commands enable database administrators and developers to
create, modify, and delete database objects such as tables,
indexes, and constraints.
The CREATE TABLE statement is used to create a
new table in a database.
Syntax:
CREATE TABLE table_name (column1_name datatype, column2_name
datatype, column3_name datatype,....);

Example:Get your own SQL Server


CREATE TABLE Persons (PersonID int, FirstName varchar(255), LastName
varchar(255),Address varchar(255),City varchar(255));

Output: Select * from Persons


Create Table Using Another Table

Syntax:
CREATE TABLE new_table_name AS SELECT column1, column2,... FROM
existing_table_name;

Example:
CREATE TABLE TestTable AS SELECT sid, sname, course FROM students;

Students Table(Existing Table) Output: Select * from TestTable


ALTER COMMAND:-

The ALTER command is a part of Data Definition Language (DDL) and


modifies the structure of a table. The ALTER command statement in Structured
Query Language allows you to add, modify, and delete columns of an existing table.
This statement also allows database users to add and remove various SQL
constraints on the existing tables.

• Syntax:- ALTER TABLE table name [alter option ...];


1. Adding a New Column Using the ALTER Command
We can add a new column to an existing table using the ALTER command
in SQL. In this example, we will add a new column E_Total in the Salary table.
Alter Table Salary
Add E_total Number;
Select * From Salary;
Output:-
2. Modifying an Existing Column With the ALTER Command in SQL
In this example, we will modify the name of the E_Total column that
we just created in the previous section.
Alter Table Salary
Rename Column E_total To E_total_salary;
Select * From Salary;
Output:-
3. Dropping an Existing Column With the ALTER Command
We can drop any existing column from a table with the ALTER Command in
SQL. Here’s an example where we will drop the E_Total_Salary column.
Alter Table Salary
Drop Column E_total_salary;
Select * From Salary;
Output:-
DROP TABLE COMMAND
DEFINITION : DROP is a type of DDL Command. By using DROP statement, the
objects are permanently deleted or lost from a database, and they cannot be rolled
back it removes the entire structure/schema of the table or the entire database.
•If we wish to insert values in the same
table, it need to be recreated first and
then only the values can be inserted.

SYNTEX: The syntax for SQL DROP Command is quiet similar to that of TRUNCATE
command except for the DROP keyword that is used in DROP command.
 FOR EXAMPLES
 Assume we have created a table named CUSTOMERS using the CREATE TABLE statement as shown below −

 Customers table is ready in database , so let us now drop it with the help of ‘’DROP COMMAND’’.
Rename
InCommand:
My SQL, the RENAME Command is used to rename database objects such as
tables, columns, indexes, and views.
Syntax :
RENAME TABLE Current_table_name TO new_table_name;
For Example :
Rename table Employees TO Staff ;

Employees Output: Staff


Emp ID EMP Name DOB Emp ID EMP Name DOB

01 John 14/07/1988 01 John 14/07/1988

02 Harry 29/10/1985 02 Harry 29/10/1985


MySQL does not have a direct RENAME COLUMN Command. To rename a column, you
typically need to use the ALTER TABLE statement with the CHANGE clause.

Syntax :

ALTER TABLE table_name CHANGE old_column_name new_column_name


column_definition ;

Example : Rename Pincode TO Zipcode In The Employee Table.


EMPId FirstName LastName Pincode EMPId FirstName LastName Zipcode

125 Harry Porter 123456 125 Harry Porter 123456


Truncate Statement
Truncate Statement:
1. used to delete all the rows of a table.

2 Delete can also be used to delete all the rows from the table.
3 The difference is that delete performs a delete operation
on each row in the table and the database performs all
attendant tasks on the way.

4 On the other had the Truncate statement simply throws away


all the rows at once and is much quicker.

5 If there are dependencies requiring integrity checks we should


use delete.
Syntax:

TRUNCATE TABLE table_name

Example:
TRUNCATE TABLE studios

This deletes all the rows of the table studios


Thank you!

You might also like