Monday, 21 September 2015



Data Definition Language (DDL)


This is first Sub Language of SQL which is used to defining the Database object like Table. View, Procedure, Function, and Trigger etc. in this sub language has predefine syntax for describing the data.

Data Definition Language (DDL) is used for create, altering, renaming and deleting the schema object from. This Sub Language Contains 5 Commands. Those are

1: CREATE

2: ALTER

3: RENAME

4: TRUNCATE

5: DROP

CREATE:

This Command is used to create Database object such as table, view, synonyms etc.

Syntax:

create table table_name (column_1 datatype(size), column_2 datatype(size), column_3 datatype(size)…… column_n datatype(size));

The Example of CREATE Commands

create table student(Roll_no number(10) , Student_name varchar2(20), Dept_name varchar2(5));

Rules for creating table:

Table must start with an alphabet and it contains minimum one and maximum 30 character, it does not allows space or any other special character such as _,#,$,0-9 numbers.
Oracle does not allow the reserve or data type in table names or columns name.

A Table has minimum 1 and maximum 1000 columns (from the oracle 9i onwards) A table can store minimum 0 record and maximum n numbers of records (capacity of HDD).

ALTER:

This Command is used to modify the structure of the table.
Using this command we can perform 4 different operations on the table.

ALTER-MODIFY

This Command is used to increase or decrease the size of the column or we can change the data type of column.

Syntax:

Alter table table_name modify column name datatype(size);

Exmple:

Alter table student modify(student_name char(20));

ALTER-ADD

This Command is used to Add one or more than one column in table.

ALTER-RENAME

This Command is used to change the column name and also table name.

ALTER-DROP

This Command is used to remove the column from the exiting table.

RENAME:

This command is used to change the table name.
Syntax:

Rename old_table_name to new_table_name;

Example:

Rename student to scholar;

TRUNCATE:

This command is used to delete te record from the existing table permanently.

DROP:

This command is used to remove the table form the database.

Syntax:

Drop table table_name;

Example:

Drop table student;

NOTE:
Other DDL commands FLASHBACK Command PURGE Command


No comments:

Post a Comment