EXPERIMENT NO: 1
DATA DEFINITION LANGUAGE (DDL) COMMANDS
To execute and verify the Data Definition Language commands.
OBJECTIVES
To understand DDL commands.
THEORY
The commands used are:
®@ CREATE - It is used to create a table.
e ALTER = The structure of a table can be modified by using the ALTER
TABLE command. This command is used to add a new column, modify the
existing column definition and to include or drop integrity constraint.
e DROP - It will delete the table structure provided the table should be empty.
@ TRUNCATE - If there is no further use of records stored in a table and the
structure has to be retained, and then the records alone can be deleted.
# DESC - This is used to view the structure of the table
PROCEDURE
CREATION OF TABLE:
SYNTAX:
create table
(column! datatype,column2 datatype...);
EXAMPLE:
SQL>CREATE TABLE Employee ( EmpNo number(5), EName VarChar(15),
Job Char(10) , DeptNo number(3));
ALTER TABLE(a) To Add column to existing Table
‘Syntax:
alter table table-name add(column-name datatype );
ALTER TABLE Employee ADD (phone_no char (20);
(b)To Add Multiple columns to existing Table
‘Syntax:
alter table table-name add(column-namel datatype, column-name2
datatype2, eolumn-name3 datatype3);
EXAMPLE:
alter table Employee add(salary number(7), age(5));
(c) Dropping a Column from a Table
‘Syntax:
ALTER TABLE DROP COLUMN ;
EXAMPLE:
ALTER TABLE Employee DROP COLUMN phone_no ;
(d) Modifying Existing Columns
‘Syntax:
ALTER TABLE MODIFY (());,
EXAMPLE:
ALTER TABLE Employee MODIFY (EName VarChar(25));(e) To Rename a column
Using alter command we ean rename an existing column
Syntax:
alter table fable-name rename old-column-name to column-name ;
EXAMPLE:
alter table Employee rename address to Location;
RENAMING TABLES:
Syntax:
Rename to ;
EXAMPLE:
rename Employee to Employee 1;
TRUNCATE TABLE
Syntax:
TRUNCATE TABLE ;
Example:
Truncate table Employee;
DESTROYING TABLES:
Syntax:
DROP TABLE ;
Example:
DROP TABLE Employee;DESCRIBE TABLES
‘Syntax:
DESC ;
Example:
dese employee:
RESULT:
The DDL commands have been executed successfully
Problems
1 Create the tables described below
Table Name : PRODUCT_MASTER
Description used to store product information
‘Column name Data type size
PRODUCTNO: Varchar2 6
DESCRIPTION Varchar2 5
PROFITPERCENT Warchar2 42
UNITMEASURE Warchar2 10
QTYONHAND Number 8
REORDERLVL Number 8
SELLPRICE Number B2
COSTPRICE Number 82
Table Name : CLIENT_MASTER,Description _: used to store client information
Column name Data type size
CLIENTNO Varchar2 6
NAME Varchar2 20
ADDRESS1 Varchar2 30
ADDRESS? Varchar2 30
cITY Varchar2: 15
PINCODE Number 8
STATE Varchar2, 15
BALDUE Number 10,2
Table Name : SALESMAN MASTER
Description : used to store salesman information working for the company
Column name Data type size
SALESMANNO- Varchar2: 6
SALESMANNAME Varchar2 20
ADDRESS| Varchar2, 30
ADDRESS2 Varchar2 30
cITY Varchar2 15
PINCODE Number 8
STATE Varchar2 15Table Name ;: STUDENT
Description used to store student information
Column name Data type size
SNO Number 3
SNAME Varehar2 20
AGE Number 3
SDOB Date
SMARKI Number az
SMARK2 Number 42
SMARK3 Number a4
2. Exercise on altering the table structure
(a) Add a column called ‘telephone’ of data type ‘number’ and size ="10" to the
Client _Master table.
(b)Change the size of Sellprice column in Produet_Master to 10,2
3. Exercise on deleting the table structure along with the data
(a)Destroy the table Client_Master along with its data
4, Exercise on renaming the table
(a)Change the name of the Salesman_Master table to sman_mast