What is DDL?
DDL is used to create, modify, and delete database objects such as databases, tables, and schemas.
CREATE
ALTER
DROP
TRUNCATE
RENAME
CREATE - The CREATE statement is used to create a new database or a new table.
CREATE TABLE table_name(
column1 datatype,
column2 datatype
);
CREATE TABLE Student(
Student_ID INT,
Name VARCHAR(50),
Marks INT
);
ALTER - The ALTER statement is used to modify the structure of an existing table.
ALTER TABLE table_name
ADD column_name datatype;
ALTER TABLE Student
ADD Department VARCHAR(50);
DROP - The DROP statement is used to permanently delete a database or table.
DROP TABLE table_name;
DROP TABLE Student;
TRUNCATE - The TRUNCATE statement removes all records from a table but keeps the table structure.
TRUNCATE TABLE table_name;
TRUNCATE TABLE Student;
RENAME - The RENAME statement changes the name of a table.
ALTER TABLE old_table_name
RENAME TO new_table_name;
ALTER TABLE Student
RENAME TO Student_Details;
Top comments (0)