DDL | Data Definition Language
DDL or Data Definition Language actually consists of the SQL commands that can be used to define the database schema.
•CREATE – is used to create the database or its objects (like table, index, function, views, store procedure and triggers).
•DROP – is used to delete objects from the database.
•ALTER – is used to alter the structure of the database.
•TRUNCATE – is used to remove all records from a table, including all spaces allocated for the records are removed.
•COMMENT – is used to add comments to the data dictionary.
•RENAME – is used to rename an object existing in the database.
"CREATE"
create table mytab( c1 int, c2 varchar(255))
create table mytab1( C1 int NOT NULL, c2 varchar(255))
create table mytab2( C1 int NOT NULL UNIQUE, c2 varchar(255))
create table mytab3( C1 int NOT NULL PRIMARY Key, c2 varchar(255))
create table mytab4( C1 int , c2 varchar(255), PRIMARY KEY (c1,c2))
create table mytab5( c1 int, c2 int, c3 varchar(200), PRIMARY KEY (c1,c3), FOREIGN KEY (c2) REFERENCES mytab3(c1))
create table mytab6( c1 int PRIMARY KEY, c2 varchar(255), c3 varchar(50) DEFAULT 'KARACHI');
create table mytab7( c1 int PRIMARY KEY, c2 varchar(255), c3 int CHECK (c3>=10) );
create table mytab8( c1 int PRIMARY KEY, c2 varchar(255), c3 int, CHECK (c1>15 AND c3>=10) );
"DROP"
drop table mytab8 truncate table mytab1
"ALTER"
•ALTER TABLE - ADD Column
ALTER TABLE mytab1
ADD c5 int
ALTER TABLE mytab1
ADD c6 int
ADD c7 int
• DROP Columns
ALTER TABLE mytab1
DROP column c6
ALTER TABLE mytab1
DROP (c5,c2)
ALTER TABLE mytab1
modify c7 varchar(100)
Want to get digital services? Contact US
Want to know about our services? Our Services
Comments
Post a Comment