0% found this document useful (0 votes)
2 views13 pages

DDL commands of SQL

The document outlines DDL commands used in databases, specifically focusing on the ALTER TABLE, TRUNCATE, and DROP commands. It details how to modify table structures, remove all records efficiently with TRUNCATE, and the irreversible nature of the DROP command. Additionally, it compares the TRUNCATE command with DROP and DELETE, highlighting their differences in functionality and recovery options.

Uploaded by

chintan.raval
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views13 pages

DDL commands of SQL

The document outlines DDL commands used in databases, specifically focusing on the ALTER TABLE, TRUNCATE, and DROP commands. It details how to modify table structures, remove all records efficiently with TRUNCATE, and the irreversible nature of the DROP command. Additionally, it compares the TRUNCATE command with DROP and DELETE, highlighting their differences in functionality and recovery options.

Uploaded by

chintan.raval
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 13

DDL Commands

•FIRST COMMANDS TO DEAL WITH DATABASE


•CREATE, ALTER, RENAME, DROP, TRUNCATE
ALTER TABLE Statement

• The ALTER TABLE statement is used to add,


delete, or modify columns in an existing table.

• The ALTER TABLE statement is also used to


add and drop various constraints on an existing
table.
ALTER TABLE Statement

►To add a column in a table, use the


following syntax:

► ALTER TABLE table_name


ADD column_name datatype;
ALTER TABLE Statement

►To delete a column in a table, use


the following syntax :

►ALTER TABLE table_name


DROP COLUMN column_name;
ALTER TABLE Statement

►To change the data type of a


column in a table, use the following
syntax:

►ALTER TABLE table_name


MODIFY column_name datatype;
EXAMPLES :

►ALTER TABLE Persons


ADD DateOfBirth date;
►ALTER TABLE Persons
MODIFY name varchar2(30);
►ALTER TABLE Persons
DROP COLUMN DateOfBirth;
TRUNCATE COMMAND

► The Truncate SQL command is used to delete all


records from an existing oracle table.
► Removing rows with the TRUNCATE TABLE
statement can be faster than removing all rows
with the DELETE statement, especially if the
table has numerous triggers, indexes, and other
dependencies.
TRUNCATE
COMMAND
►Truncate drops the table first and then
recreates only the table structure which is
much faster than deleting the records one by
one.
► Hence in case a table contains large number
of records, it works much faster than delete
statement.
TRUNCATE
COMMAND
► Syntax :
TRUNCATE TABLE TABLE_NAME;

► Example:
1. TRUNCATE TABLE EMP;
2. TRUNCATE TABLE DEPARTMENT;
DROP COMMAND
► The DROP command is used to remove an object
from the database.
► If u drop a table, all the rows in the table is deleted
and the table structure is removed from the
database.
► Once a table is dropped we cannot get it back, so be
careful while using drop command.
► When a table is dropped all the references to the
DROP COMMAND
► Syntax:
DROP TABLE TABLE_NAME;

► Example:
DROP TABLE EMP;
DROP TABLE DEPARTMENT;
Difference
TRUNCATE DROP
Truncate command removes all Drop command removes all records
records from the specified table, but from the table along with the table
keeps structure of the table intact. structure and puts it in recycle bin.

The records once deleted with The table removed with the drop
truncate command cannot be command can be recovered from the
recovered with the help of rollback. recycle bin with the help of flashback
command.
Difference
TRUNCATE DELETE
Truncate command removes all Delete command can delete one
records from the specified table. or more records from the table.

The records once deleted with The records once deleted with
truncate command cannot be delete command can be
recovered with the help of recovered with the help of
rollback. rollback.

You might also like