Professional Documents
Culture Documents
Implement Data Definition Language commands -Create, Alter, Drop, Truncate, and Rename.
1. CREATE :
Purpose:
To create a table in the database.
Syntax:
• Create table <table name> (column definition);
Using primary key:
• Create table <table name>
(column 1 datatype NULL/ not NULL,column 2 datatype NULL/not NULL-----------, Constraint
constraint_name primary key column 1,column2,- -(column –n));
EXAMPLE QUERIES:
a. Create a table called employee with following attributes.
i. Employee no
ii. Employee name
iii. Department number
SQL>create table employee(eno number(3),ename varchar2(20),dno number(3));
OUTPUT:
Table created.
2. DESC:
Purpose:
To display the table structure.
Syntax:
• Desc<table name>
EXAMPLE QUERIES:
Command to give the structure of the employee table.
SQL> desc employee.
OUTPUT:
NAME NULL? TYPE
------------ ------- -----------
ENO NUMBER(3)
ENAME VARCHAR2(20)
DNO NUMBER(3)
3.ALTER:
Purpose:
To alter the structure of the table in the database.
Syntax:
SQL>desc employee.
OUTPUT:
NAME NULL? Type
----------- --------------------------
ENO NUMBER(3)
ENAME VARCHAR2(30)
DNO NUMBER(3)
EXAMPLE QUERIES:
Command to modify the data type of the field ENO.
SQL>alter table employee modify(eno number(5));
OUTPUT:
Table created.
SQL>desc employee;
NAME NULL? TYPE
----------- --------------------------
ENO NUMBER(5)
ENAME VARCHAR2(30)
DNO NUMBER(3)
SAL NUMBER(12,2)
• Alter table <table name> rename column<old column name>to<new column name>
EXAMPLE QUERIES:
Command to rename the column name
SQL>alter table employee rename column ename to empname.
OUTPUT:
Table altered.
SQL>desc employee;
NAME NULL? TYPE
----------- --------------------------
ENO NUMBER(5)
EMPNAME VARCHAR2(30)
DNO NUMBER(3)
SAL NUMBER(12,2)
4. DROP:
Purpose:
To remove the table from the database.
Syntax:
• Drop table<table name>
EXAMPLE QUERIES:
Command to drop the employee table
SQL>drop table employee.
OUTPUT:
Table droped.
SQL> desc employee
ERROR:
ORA-04043: object employee does not exist
5.TRUNCATE:
Purpose:
To remove the entire content of the table from the database.
Syntax:
• Truncate table<table name>
EXAMPLE QUERIES:
SQL>truncate table employee
OUTPUT:
Table truncated.
SQL>select *from employee;
no rows selected.
Result:
Thus, the DDL commands are executed.