9. Data Definition Language
9. Data Definition Language
DDL
Data Definition language:
• Data Definition Language actually consists of the SQL commands that can
be used to define the database schema.
• It simply deals with descriptions of the database schema and is used to
create and modify the structure of database objects in the database.
• DDL is a set of SQL commands used to create, modify, and delete database
structures but not data.
• CREATE
• ALTER
• COMMENT
• RENAME
• TRUNCATE
• DROP
Create Command:
• The Create command is used to create a new
database or a new component in the database
like tables, stored procedure, index, etc.
Create Command:
• Creating Table using create command.
desc Command:
We implement the DESCRIBE TABLE statement for getting the info about the
name of the column, data type of the column, NULL or NOT NULL attributes of
column, and table with database size accuracy along with If NUMERIC type scale.
Alter Command:
• Alter commands are used to modify the tables to add,
rename, edit or delete a column. Alter command can also
rename the table itself.
• Add a column
Alter Command:
• The Alter Table command allows us to modify an existing
column in an existing table. This is useful when modifying the
type or the size of the column.
• An important thing to keep in mind is that we cannot rename
a column with the modify sub-command. To rename, there is
a separate sub-command.
Alter Command:
• The Alter Table command allows us to rename
a table.
Alter Command:
• The Alter Table command allows us to rename
a column in an existing table.
Delete a column:
• The Alter Table command allows us to delete a
column and its entire data from an existing
table.
Drop table:
• The DROP commands are used to delete objects from the
database or the schema. It can delete a table, view, stored
procedure, index or even a database.
Drop database:
• Drop Database command deletes the
database and all the objects in it.
Truncate:
• Truncate table command is used in MySQL to
delete all the rows present in the particular
table of the database.