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.
- used to add, delete, or modify columns in an existing table,
- And used to add and drop various constraints on an existing table
-
Alter DB
ALTER DATABASE DB_NameMODIFY NAME = New_Name; -
Add Column: To add a column in a table
ALTER TABLE table_nameADD column_name datatype;ALTER TABLE table_nameDROP COLUMN column_name;ALTER TABLE table_nameMODIFY 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;