0% found this document useful (0 votes)
193 views6 pages

SQL DDL Commands: (Create, Alter, Drop, Rename and Truncate)

The SQL DDL commands covered are create, alter, drop, rename and truncate. Create is used to create database objects like tables and views. Alter modifies the structure of existing tables by adding, dropping or renaming columns. Drop removes database objects entirely. Rename changes the name of tables or columns. Truncate quickly empties all data from a table for reuse without removing the table.

Uploaded by

praveen kumar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
193 views6 pages

SQL DDL Commands: (Create, Alter, Drop, Rename and Truncate)

The SQL DDL commands covered are create, alter, drop, rename and truncate. Create is used to create database objects like tables and views. Alter modifies the structure of existing tables by adding, dropping or renaming columns. Drop removes database objects entirely. Rename changes the name of tables or columns. Truncate quickly empties all data from a table for reuse without removing the table.

Uploaded by

praveen kumar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 6

SQL DDL Commands

{create, alter, drop, rename and truncate}

CREATE :

Create is used to create the database or its objects (like table, index, function,
views, store procedure and triggers).

Create table syntax:


Create table <table_name> (col1 datatype1, col2 datatype2 …...coln datatypen);

Output:
ALTER:
Alter statement can add a column, modify a column, drop a column, rename a
column or rename a table.

alter command is used for altering the table structure, such as,

 to add a column to existing table


 to rename any existing column
 to change datatype of any column or to modify its size.
 to drop a column from the table.

ALTER Command: Add a new Column


Using ALTER command we can add a column to any existing table. Following
is the syntax:
ALTER TABLE table_name ADD (column_name datatype);

ALTER Command: Modify an existing Column


ALTER command can also be used to modify data type of any existing column.
Following is the syntax:
ALTER TABLE table_name MODIFY (column_name datatype);

Output:
RENAME:
Sometimes we may want to rename our table to give it a more relevant name.
For this purpose we can use ALTER TABLE to rename the name of table.
Syntax:
ALTER TABLE table_name RENAME COLUMN old_col_name TO
new_col_name;

Output:
DROP:
DROP is used to delete a whole database or just a table.The DROP statement
destroys the objects like an existing database, table, index, or view.
A DROP statement in SQL removes a component from a relational database
management system.

Syntax:
DROP object object_name;

Output:
TRUNCATE:
TRUNCATE statement is a Data Definition Language (DDL) operation that is
used to mark the extents of a table for deallocation (empty for reuse). The result
of this operation quickly removes all data from a table, typically bypassing a
number of integrity enforcing mechanisms.
Syntax:
TRUNCATE TABLE table_name;

Output:

You might also like