DDL- (Data Definition Language)

These commands help you to manage the database structure. When you execute DDL commands then auto-commit takes place at the end of the transaction. The lists of DDL Commands are.

1) CREATE


This command is used to create database and database objects.


Example


To create a database


CREATE DATABASE DB1;


To create objects in the database


CREATE TABLE L1(

A NUMBER(4)
);

2) DROP


This command is used to drop database and database objects.


Example


To drop database


DROP DATABASE DB1;


To drop objects in the database


DROP TABLE L1;


3) ALTER


This allows you to rename an existing table and It can also be used to add, modify, or drop a column from an existing table.


Example


To add a column to a table


ALTER TABLE L1 ADD B VARCHAR2(4) NOT NULL;


To drop a column from a table


ALTER TABLE L1 MODIFY B NUMBER(5);


To modify a column from a table


ALTER TABLE L1 DROP COLUMN B;


To rename a database object


ALTER TABLE L1 RENAME TO L2;


4) RENAME


This command is used to rename an object in the database.


Example


RENAME L60 TO T1;


5) TRUNCATE


It deletes all data from the table. Actually, truncate doesn’t remove data but de-allocates whole Data pages and pointers to index.


Example


TRUNCATE TABLE L1;

  •  It is much faster.
  •  We can’t use condition if a statement contains Truncate.
  •  A trigger doesn’t fire on truncate.
  •  It cannot be rolled back.

6) COMMENTS

Example


To create comment on column


COMMENT ON COLUMN EMPL.FNAME IS 'MAIDON NAME';


To alter comment on column


COMMENT ON COLUMN EMPL.FNAME IS 'MAIDON NAME IS FATHER NAME';


To drop comment on column


COMMENT ON COLUMN EMPL.FNAME IS '';







No comments:

Post a Comment