Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

IT257-DBMS 21IT038

PRACTICAL -2

Aim: Perform Data Definition Language (DDL) commands and change the
existing schema as per given information.

Theoretical Description:
1) Create table supplier from employee with all the columns.
2) Create table sup1 from employee with first two columns.
3) Create table sup2 from employee with no data.
4) Insert the data into sup2 from employee whose name is ‘Anita’.
5) Rename the table sup2.
6) Destroy table sup1 with all the data.
7) Add one column phone to employee with size of column is Varchar2(10).
8) Modify column phone and change type to char(10).
9) Delete employee_name column from sup2.
10) Rename the column salary to new_sal in sup2.

Query-1: Create table supplier from employee with all the columns.

SQL Query :
1. create table SUPPLIER as select * from TABLE_EMPLOYEE;
2. desc SUPPLIER;
Output:
Table SUPPLIER created.

CSPIT K.D. Patel Department of Information Technology Page 1


IT257-DBMS 21IT038

Query-2: Create table supplier2 from employee with first two columns.

SQL Query :
1. create table SUPPLIER2 as select EMP_NO, EMP_NAME from
TABLE_EMPLOYEE;
2. DESC SUPPLIER2;

Output:
Table SUPPLIER2 created.

CSPIT K.D. Patel Department of Information Technology Page 2


IT257-DBMS 21IT038

Query-3: Create table SUPPLIER3 from employee with no data.

SQL Query :

1. create table SUPPLIER3 as select * from TABLE_EMPLOYEE where


EMP_NO=115;
2. select * from SUPPLIER3;

Output:
Table SUPPLIER3 created.

CSPIT K.D. Patel Department of Information Technology Page 3


IT257-DBMS 21IT038

Query-4: Insert the data into SUPPLIER3 from employee whose name is ‘Anita’.

SQL Query :

1. insert into SUPPLIER3 select * from TABLE_EMPLOYEE where


EMP_NAME='Anita';
2. desc SUPPLIER3;
3. SELECT * FROM SUPPLIER3;

Output:
1 row inserted

CSPIT K.D. Patel Department of Information Technology Page 4


IT257-DBMS 21IT038

Query-5: Rename the table SUPPLIER3.

SQL Query:

1. RENAME SUPPLIER3 To SUPP3;


2. desc SUPP3;

Output:
Table renamed

CSPIT K.D. Patel Department of Information Technology Page 5


IT257-DBMS 21IT038

Query-6: Destroy table SUPPLIER2 with all the data.

SQL Statement:

1. drop table SUPPLIER2;


2. desc SUPPLIER2;

Output:
Table SUPPLIER2 dropped.
ERROR:
ORA-04043: object SUPPLIER2 does not exist -

Query-7: Add one column phone to employee with size of column is Varchar2(10).

CSPIT K.D. Patel Department of Information Technology Page 6


IT257-DBMS 21IT038

SQL Query :

1. alter table TABLE_EMPLOYEE add (phone char(10));


2. desc TABLE_EMPLOYEE;

Output:
Table TABLE_EMPLOYEE altered.

Query-8: Modify column phone and change type to number(10).

CSPIT K.D. Patel Department of Information Technology Page 7


IT257-DBMS 21IT038

SQL Query :

1. alter table TABLE_EMPLOYEE modify (phone number(10));


2. desc TABLE_EMPLOYEE;

Output:
Table TABLE_EMPLOYEE altered.

Query-9: Delete employee_name column from SUPPLIER1.

SQL Query:

CSPIT K.D. Patel Department of Information Technology Page 8


IT257-DBMS 21IT038

1. alter table SUPPLIER1 drop column EMP_NAME;


2. desc SUPPLIER1;

Output:
Table SUPPLIER1 altered.

Query-10: Delete employee_name column from supplier.

SQL Query:

1. alter table SUPPLIER rename column EMP_SAL to NEW_SAL;

CSPIT K.D. Patel Department of Information Technology Page 9


IT257-DBMS 21IT038

2. desc SUPPLIER;

Output:
Table SUPPLIER altered.

CSPIT K.D. Patel Department of Information Technology Page 10

You might also like