Relational Query Languages | Data Definition language(DDL)
DDL(Data Definition Language)
The Data Definition Language (DDL) manages table and index structure.
COMMAND USED- CREATE, ALTER, DROP,RENAME
CREATE creates an object (a table) in the database.
ALTER modifies the structure of an existing object in various ways, for example, adding a column to an existing table or a constraint.
DROP deletes an object in the database, usually irretrievably, i.e., it cannot be rolled back.
RENAME rename scheme object
The Data Definition Language (DDL) manages table and index structure.
COMMAND USED- CREATE, ALTER, DROP,RENAME
CREATE creates an object (a table) in the database.
ALTER modifies the structure of an existing object in various ways, for example, adding a column to an existing table or a constraint.
DROP deletes an object in the database, usually irretrievably, i.e., it cannot be rolled back.
RENAME rename scheme object
1. CREATE COMMAND-This
command is used when we want to create a new table.
syntax: create table <tname> (col.1 data type (size) constraint
<constraint name> not null , col.2 data type (size));
E.g.:
create table mydoc1 (username varchar (20) constraint name_mn not null,
password number(10));
2. ALTER COMMAND- This
command is used when we want to delete a particular column from a existing
table.
We use three clauses with alter
command:
1. ADD
2. MODIFY
3. DROP
· ADD: This command is used when we
want to create a new column.
syntax:
alter table tname add (col. name data type (size));
E.g.:
alter table student add (Roll no. number(100));
· MODIFY: This command is used when we
want to modify the table.
syntax: alter table tname modify (col.
name data type(size));
E.g.:
alter table emp modify (Branch
varchar(20));
3. DROP COMMAND- This command is used when we
want to drop a table.
syntax: alter table tname drop column
(col. name);
E.g.:
alter table emp drop column salary;
4.RENAME COMMAND-Rename scheme object
SYNTAX- alter table <tname> RENAME COLUMN (old column name to new column name);
E.G.- alter table emp RENAME COLUMN (name to empname);
0 comments:
Post a Comment