Create,Alter,Modify

 Syntax:
CREATE TABLE table_name
( column1 datatype null/not null,
  column2 datatype null/not null,
  ...
);
  Example

        

CREATE TABLE EMPLOYEE_DETAILS(EMPNAME VARCHAR2(20),EMPAGE INT,EMPSALARY NUMERIC(6,2),EMPDESIGNATION VARCHAR2(20))
OutPut
         
   
                  We can edit the structure of a table by using a keyword 'ALTER'.
                  

Renaming a table

 syntax :
 
  ALTER TABLE table_name
  RENAME TO new_table_name;

 example:
ALTER TABLE suppliers
 RENAME TO vendors;
This will rename the suppliers table to vendors.

Adding column(s) to a table

Syntax :

      To add a column to an existing table, the ALTER TABLE syntax is:
ALTER TABLE table_name
 ADD column_name column-definition;
 example:
ALTER TABLE supplier
 ADD supplier_name  varchar2(50);
    This will add a column called supplier_name to the supplier table.

Modifying column(s) in a table

Syntax :

     To modify a column in an existing table, the ALTER TABLE syntax is:
ALTER TABLE table_name
 MODIFY column_name column_type;
 example:
ALTER TABLE supplier
 MODIFY supplier_name   varchar2(100)     not null;
This will modify the column called supplier_name to be a data type of varchar2(100) and force the column to not allow null values.


                              We can drop particular fields from the table.

Drop column(s) in a table

Syntax :
  
      To drop a column in an existing table, the ALTER TABLE syntax is:
ALTER TABLE table_name
 DROP COLUMN column_name;
 example:
ALTER TABLE supplier
 DROP COLUMN supplier_name;
This will drop the column called supplier_name from the table called supplier.

Comments

Popular posts from this blog

Introduction To Oracle10g

Insert

Except