What is DDL (Data Definition Language)?

Data Definition Language (DDL) is used to specify or create database schema like new database or tables creation along with their properties. It also helps in the alteration and creation of tables, indexes, files, columns, etc within the database. It allows us to create the skeleton of the database.

Some operations that we can perform on the database using DDL:

  • CREATE – It is used to create a new database or object.

The syntax for creating table –

CREATE TABLE [table name] ([column definitions]) [table parameters];

The syntax for creating a Database –

CREATE DatabaseName;
  • ALTER – It is used to alter the structure of the database ie. modifying the existing database.

Syntax –

ALTER [object-type] [object-name] parameters;
  • DROP – It is used to delete objects such as tables, indexes, etc. from the database. After deleting an object, we can’t recover it. 

Syntax –

DROP [object-type] [object-name];
  • TRUNCATE – It is used to remove all records from a table.

Syntax –

TRUNCATE TABLE [table_name];
  • RENAME – It is used to rename the database or object.

Syntax –

RENAME TABLE old_table_name to new_table_name