Skip to content

DDL Commands

DDL or Data Definition Language actually consists of the SQL commands that can be used to defining, altering, and deleting database structures such as tables, indexes, and schemas. It simply deals with descriptions of the database schema and is used to create and modify the structure of database objects in the database.

The main DML commands are:

  • CREATE
  • ALTER
  • TRUNCATE
  • DROP

CREATE

This command is used to create databases or tables.
The code for this is given below-

  • Create Database:
    CREATE DATABASE DB_Name;
  • Create table:
    CREATE TABLE table_name (
    column1 datatype,
    column2 datatype,
    column3 datatype,
    ....
    );

ALTER

This is used to modify the database or table that you have just created.

  1. used to add, delete, or modify columns in an existing table,
  2. And used to add and drop various constraints on an existing table
  • Alter DB

    ALTER DATABASE DB_Name
    MODIFY NAME = New_Name;
  • Add Column: To add a column in a table

ALTER TABLE table_name
ADD column_name datatype;
* Drop Column: To delete a column in a table

ALTER TABLE table_name
DROP COLUMN column_name;
* Modify Column: To change the data type of a column in a table

ALTER TABLE table_name
MODIFY COLUMN column_name datatype;

TRUNCATE

This command is used to remove all the rows from the table. To delete the data inside a table, but not the table itself.

TRUNCATE TABLE table_name;

DROP

This command is used to drop databases, tables, or any other entities related with databases.

  • Drop Database:
    DROP DATABASE databasename;
  • Drop table:
    DROP TABLE table_name;