Friday, March 29, 2019

DDL Commands | Data Definition Language | SQL Commands

Data Definition Language

In SQL, there are following types of DDL commands. As below

  • DROP
These DDL commands are used to creating, modifying and dropping the structure of database object.
These DDL commands are auto-committed that means it permanently save all the changes in the database.

CREATE Command

Create command used to create new table in a database.

Syntax : 

CREATE TABLE table_name (column_name1 datatype, column_name2 datatype, column_name3 datatype, column_name4 datatype,  . . .) ;

In create command, there is one type of parameters:

1) column_name - This parameter specify the name of the column.

Example :

// Create new Customer01 table

CREATE TABLE Customer01 (Cust_Id int,Last_Name varchar(255),
First_Name varchar(255),Address varchar(255),City varchar(255));

  • Above, example creates a table called "Customer01" that contains five columns: Cust_Id, Last_Name, First_Name, Address, and City.
  • The Cust_Id column is of type int and will hold an integer.
  • The Last_Name, First_Name, Address, and City columns are of type varchar and will hold characters, and the maximum length for these fields is 255 characters.

DROP Command

Drop command used to remove existing table definition and all data from database.

Syntax :

DROP TABLE table_name;

In Drop command, there is one type of parameter:

1) table_name - This parameter specifies the name of table, which we want to drop.

Example :

// Drop Customer01 table 

DROP TABLE Customer01:

ALTER Command

Alter command used to add, modify and drop or delete columns or constraints on an existing table.

Syntax :

ALTER TABLE table_name ADD column_name datatype /
                                              MODIFY COLUMN column_name datatype /
                                              DROP COLUMN column_name ;

In ALTER command, there is three types of  Keywords :

1) ADD - This keyword used to add new column in existing table.
2) MODIFY - This keyword used to update or change name of existing column.
3) DROP - This keyword used to drop column from an existing table.

In ALTER command, there is one type of parameter :

1) column_name - This parameter used to  specifies name of column.

Example :

//Add new column

1) ALTER TABLE Customer01 ADD Registration_No int;

//Modify existing column name
2) ALTER TABLE Customer01 MODIFY COLUMN Last_Name varchar(30);

//Drop City column

3) ALTER TABLE Customer01 DROP City ;


Truncate command used to delete data from database or table.

Syntax :

TRUNCATE TABLE table_name;

Example :

// Truncate Customer01 table


* * * * * * * * * * * * * * * *

In Easy Language(Simplify)

CREATE - This command used to create new table in existing database.

DROP - This command used to drop or delete existing table definition from database.

ALTER - This command used to add,modify or drop columns.

TRUNCATE - This command used to delete database from table.

Recommended :

Create | DDL Commands
DROP | DDL Commands
ALTER | DDL Commands

Previous Post
Next Post

post written by: