What Is DDL in Mysql?: - S.Manoj
What Is DDL in Mysql?: - S.Manoj
-S.MANOJ
What is DDL in MySQL?
What is DDL in MySQL?
DDL stands for data definition language. It is a set of SQL statements that work on
the database as a whole, rather than an individual table or row. Create, alter, and
drop are elements of this language. You would use these elements, when you want
to add a table, change the makeup of a table, or delete a table. These operations are
significant, changing the nature of the database in question.
DIFFERENT TYPES OF DDL COMMANDS
• CREATE- to create a database and its objects like (table, index, views, store
procedure, function, and triggers)
• ALTER - alters the structure of the existing database
• DROP - delete objects from the database
• TRUNCATE - remove all records from a table, including all spaces allocated
for the records are removed
• COMMENT - add comments to the data dictionary
• RENAME - rename an object
• CHANGE - Change Keywords allows you to change Name of
Column,Column Data Type,Column Constraints.
• MODIFY - allows you to Modify Column Data Type,Modify Column
Constraints.
SYNTAX
• CREATE
• Syntax:[code lanuage=”sql”] CREATE TABLE <table_name> (
<column_name1> <datatype1> <constraint1>
<column_name2> <datatype2> <constraint2>
<constraint-list>
);
• ALTER
• SQL command can be used to add, modify, or drop a column from the
existing table or to rename a table.
• Syntax:[code lanuage=”sql”] Alter table <table name> add <column
name><data type>;
SYNTAX
• DROP
• Syntax:[code lanuage=”sql”] Drop <table name>;
• Note: Before table drop must remove the dependent constraints
• TRUNCATE
• Syntax:[code lanuage=”sql”] TRUNCATE table <table name>;
• RENAME
• Syntax:[code lanuage=”sql”]
• ALTER TABLE table_name RENAME TO new_table_name;
SYNTAX
• COMMENT
• ALTER TABLE tablename CHANGE ‘column’’column’ COMMENT ‘ …‘;
• CHANGE
• ALTER TABLE tablename CHANGE colname colname datatype
constraint;
• MODIFY
• ALTER TABLE tablename MODIFY colname datatype constraint;
CONSTRAINTS:
• UNIQUE
• NOTNULL
• PRIMARY KEY
• AUTO_INCREMENT
• TIMESTAMP
• ORDER BY
• COMMENT
• DEFAULT
• NULL
THANK YOU