Data Definition Language(DDL)
- DDL deals with the structure of objects.
- DDL commands interact with database directly.
- DDL commands enforce an implement commit before & after statement .
- Cannot undo (rollback) the changes.
- DDL commands are faster (performance).
Here are some commands that come under DDL:
- CREATE
- RENAME
- ALTER
- TRUNCATE
- DROP
1.CREATE
This command is used to create database objects, such as table ,views etc.
Syntax
( column1 datatype(size), column2 datatype(size), …….. );
Example
2.ALTER
This command is used to modify the structure of a table
- ALTER-Modify
- ALTER-ADD
- ALTER-Rename
- ALTER-DROP
- ALTER-Modify
This command is used to increase or decrease the size of datatype and also we can change the datatype from old datatype to new datatype.
Syntax :-
ALTER TABLE
MODIFY (
Column1 datatype(size),
Column2 datatype(size),
…….
ColumnN datatype(size),
);
ii.ALTER-ADD
This command is used to ADD the new column to the existing table.
Syntax
ALTER TABLE
ADD NEW_COLUMN_NAME DATATYPE(SIZE);
Example
ALTER TABLE students_details
ADD roll_num number(8);
iii. ALTER-Rename
This command is used to change column name from old column name to new column name.
Syntax
ALTER TABLE
RENAME COLUMN old_column_name TO new_column_name;
Note
We can’t change more than one column at time.
iv. ALTER-DROP
This command is used to drop the column from the existing table.
syntax
ALTER TABLE
DROP COLUMN column_name;
EXAMPLE
ALTER TABLE student_details
DROP COLUMN roll_num;
3.RENAME
This command is used to change table name from old table name to new table name.
Syntax
RENAME old_table_name TO new_table_name;
Example
4.TRUNCATE
This is used to truncate (delete) all the records from existing table.
Syntax
TRUNCATE TABLE ;
5.DROP
This command is used to drop the table from the database.
Syntax
DROP TBALE ;
vhjgfjhgku