DDL Queries
DDL Queries
1) Create
2) Alter
3) Truncate
4) Drop
Syntax & DDL Commands
CREATE:
This command is used to create a new table in SQL. The user has to give
information like table name, column names, and their datatypes.
Syntax
This command is used to add, delete or change columns in the existing table.
The user needs to know the existing table name and can do add, delete or
modify tasks easily.
Syntax
Syntax to add a column to an existing table.
ALTER TABLE table_name ADD column_name datatype;
Example
In our Student_info table, we want to add a new column for CGPA. The
syntax would be as below as follows.
ALTER TABLE Student_info ADD CGPA number;
Continued..
TRUNCATE :
This command is used to remove all rows from the table, but the structure of
the table still exists.
Syntax
Syntax to remove an existing table.
TRUNCATE TABLE table_name;
Example
The College Authority wants to remove the details of all students for new
batches but wants to keep the table structure. The command they can use is as
follows.
TRUNCATE TABLE Student_info;
Continued..
DROP
This command is used to remove an existing table along with its structure
from the Database.
Syntax –
Syntax to drop an existing table.
DROP TABLE table_name;
Example