DDL(Data-Definition Language)

  • DDL commands used for design or defines database.
  • in DDL create,alter,truncate,drop commands include.

 CRATE

  • crate command used to create a table in database. 
  • syntax
       CRATE TABLE <table name>
                   (
                   <column 1> <datatype> (<size>),
                   <column 2> <datatype> (<size>),             
                   );
  • Example
        CREATE TABLE student
                                 (
                                  id number(6),
                                  name varchar2(30),
                                  phone number(10)
                                  );

ALTER

  • Alter command used modify structures of a table.
  • Alter command used add ,modify, or drop table columns in a table.
  • syntax
    • Adding New Columns
               ALTER TABLE <tablename>
               Add (NewColumnName Datatype(size),
                        NewColumnName Datatype(size)….);
               
               EXAMPLE
               ALTER TABLE student ADD(address varchar2(100));
    •  Modifying Existing Columns 
               ALTER TABLE TableName
               MODIFY (ColumnName  NewDatatype(NewSize));
                
                EXAMPLE
                ALTER TABLE student MODIFY(id number(10));
    • Dropping(deleting) Existing Columns
              ALTER TABLE <TableName> DROP COLUMN <columname>;
              
              EXAMPLE
              ALTER TABLE student DROP COLUMN phone
              

TRUNCATE TABLE

  •  TRUNCATE TABLE used to delete all data from a table.
  •  this command deletes all rows 
  • syntax
       TRUNCATE TABLE  <TableName>;
       
       EXAMPLE 
       TRUNCATE TABLE student;

DROP TABLE

  • DROP TABLE command is used to delete table from a database. 
  • syntax 
       DROP TABLE <TableName>;
      
       EXAMPLE 
       DROP TABLE student;