DEV Community

Punitha
Punitha

Posted on

DDL (Data Definition Language)

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
);
Enter fullscreen mode Exit fullscreen mode

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);
Enter fullscreen mode Exit fullscreen mode

DROP - The DROP statement is used to permanently delete a database or table.

DROP TABLE table_name;

DROP TABLE Student;
Enter fullscreen mode Exit fullscreen mode

TRUNCATE - The TRUNCATE statement removes all records from a table but keeps the table structure.

TRUNCATE TABLE table_name;

TRUNCATE TABLE Student;
Enter fullscreen mode Exit fullscreen mode

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;
Enter fullscreen mode Exit fullscreen mode

Top comments (0)