What is DDL ? Write any two examples of DDL.
Answers
the full form of ddl is data definition language
DDL is Data Definition Language.
DDL Statements let you perform these tasks
1.CREATING A TABLE
use the CREATE TABLE statement to create
→Relational table which is basic structure to hold the user data.
—>Object table which is a table which uses object type for column definition.
To create relational table in your own schema you must have the CREATE TABLE system privilege.
to create a table in anothers schema you must have CREATE ANY TABLE system privilege
syntax :
CREATE TABLE tablename (column1 datatype(size) constraint[optional], column2 datatype(size) constraint[optional]);
constraint is optional depending upon the requirement we have to mention constraint type.
we can create a table from another table using 'AS'
create table employee AS select * from emp;
→in above statement it creates the table and it contains same values/columns and rows of emp table in employee table.
2.ALTERING THE TABLE
use the ALTER TABLE statement to alter the definition of a nonpartitioned table, a partitioned table, a table partition, or a table subpartition.
ALTER TABLE statement is used for
→add a new column
syntax: ALTER TABLE tablename
ADD column_name datatype(size);
—>modify an existing column
syntax: ALTER TABLE tablename
MODIFY column_name datatype(size);
here,
a.we can increase or decrease the width or precision of a numeric or character column.
b. we can change one data type to another data type.
—>drop a column
syntax: ALTER TABLE tablename
DROP column_name ;
a.with ALTER TABLE statement we can drop only one column at a time
b.once column is dropped ,it cannot be recovered.