SQL DDL Commands: (Create, Alter, Drop, Rename and Truncate)
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).
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,
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: