DDL Full Form

DDL stands for Data Defination Language.
These commands are used to change the structure of a database and database objects.For example, DDL commands can be used to add, remove, or modify tables with in a database.

The DDL commands are:

  1. CREATE
  2. ALTER
  3. DROP
  4. TRUNCATE
  5. RENAME

1. CREATE :
This command is used to create table in the relational database .
This can be done by specifying the names and datatypes of various columns.

Syntax:

CREATE TABLE TABLE_NAME
(
    column_name1 datatype1,
    column_name2 datatype2,
    column_name3 datatype3,
    column_name4 datatype4
);

The column_name in create table command will tell the name of the column and corresponding datatype will specify the datatype of that column.Here in this table the three column_names namely – Student_id is of type int ,Name is of type varchar and Marks is of type int.
for example:



CREATE TABLE 
Employee
(Student_id INT, 
Name VARCHAR(100), 
Marks INT); 

Student_id

Name

Marks

2. ALTER :
Alter command is used for altering the table in many forms like:

  1. Add a column
  2. Rename existing column
  3. Drop a column
  4. Modify the size of the column or change datatype of the column
  1. ADD using ALTER –
    Syntax to add column :

    ALTER TABLE table_name ADD(
        column_name datatype); 

    The above command will add a new column to the table.And the resulting table will have one more column like this:

    ALTER TABLE Student 
    ADD
    (Address  VARCHAR(200)); 

    Here this command will add a new column “Address” in the table Student of datatype varchar(200);

    Student_id



    Name

    Marks

    Address

  2. RENAME using ALTER –
    Syntax to rename column :

    ALTER TABLE 
    table_name 
    RENAME 
    old_column_name TO new_column_name; 

    The above command will rename the existing column to new column.

    ALTER TABLE 
    Employee 
    RENAME 
    Marks TO Age; 

    The command above will change the column_name from Marks to Age;

    Student_id

    Name

    Age

    Address



  3. DROP using ALTER –
    Syntax to Drop a column :

    ALTER TABLE
    table_name
    DROp
    (column_name); 

    The above command will delete the existing column.
    For example:

    ALTER TABLE Employee 
    DROP
    (Age);  

    Here the column_name =”Age”, has been deleted by this command;

    Student_id

    Name

    Address

  4. MODIFY using ALTER –
    Syntax to Modify a column :

    ALTER TABLE
    Employee MODIFY
    (column_name datatype); 

    The above command will modify the existing column .
    For example:

    ALTER TABLE 
    student 
    MODIFY
    (name varchar(300)); 

    The above command will modify the column_name “Name” by changing the size of that column.

    Student_id



    Name

    Address

3. TRUNCATE :
This command removes all the records from a table. But this command will not destroy the table’s structure.
Syntax :

TRUNCATE TABLE table_name

This will delete all the records from the table.For example the below command will remove all the records from table student.

Example:

TRUNCATE TABLE Student; 

4. DROP :
This command completely removes the table from the database along with the destruction of the table structure.

Syntax –

DROP TABLE table_name

This will delete all the records as well as the structure of the table.
This is the main difference between TRUNCATE AND DROP.-TRUNCATE only removes the records whereas DROP completely destroys the table.

Example:

DROP TABLE Student; 

This command will remove the table records as well as destroys the schema too.

This is all about the DDL commands.

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.