Data Definition Language DDL- Create ,Alter ,Drop - Deepak YT

 Data Definition Language DDL- Create ,Alter ,Drop



  1. Create
  2. Alter 
  3. Drop
  4. Truncate
  5. Rename (orade 9i) 

A) Create:

It is used to create database objects like tables, views, sequences, indexes.
Creating a table: 
     Syntax: create table tablename (colname1 datatype(size), colname2 datatype(size), .....); 
Example:
      SQL> create table first (sno number(10), name varchar2(10), rollno number(10)); 
To view structure of the table: 
      Syntax: desc tablename; 
      Example: SQL> desc first

B) Alter:

 It is used to change structure of the existing table. 
 
Add: It is used to add number of columns into the existing table.
 
      Syntax: alter table tablename add 
                   (colname1 datatype(size), colname2 datatype(size), ............); 
Example: 
  SQL> alter table first add sal number(10);
  SQL> desc table; 
Modify: 
It is used to change column datatype or column datatype size only
Syntax: alter table tablename modify
               (colname1 datatype(size), colname2 datatype(size), .........); 
Example: 

  SQL> alter table first modify sno number(10); 

Alter...Drop:

It is used to remove columns from the existing table. 
Method1: If we want to drop a single column at a time without using parenthesis "()" then we are using
following syntax: 
 Syntax. alter table tablename drop column columnname; 
Example 
     SQL> Alter table first drop column sal; 
     SQL > desc first; 
Method2:

If we want to drop single or multiple columns with using parenthesis then we are using following
Syntax. 
     alter table tablename drop (coinamel, colname2, colname3...); 
Example:
    SOL> alter table first drop {name, rollno); 

Post a Comment

0 Comments