Dbms Lab Manual
Dbms Lab Manual
Dbms Lab Manual
DBMS LAB
Page 1
Session I
Page 2
IN
C
T_n F_na
o
me
101 111 Anga
d
10 112 shya
2
m
10 113 naufil
3
10
4
114 rohit
L_na
Sala Supervi Join_Dat
me
ry
sor
e
kamat 20
khan
04/06/20
12
lanke 5
Rahul
06/06/20
10
siddiq 10
sharma 11/03/20
ui
09
kada
15
dubey
11/03/20
m
09
DOB
Qualificati
on
11/03/199 BSc-It
2
11/12/198 MCA
0
23/05/198 BCA
5
11/03/198 Ph.D
9
Create table
create table CLA
(
CLASS_NO VARCHAR2(3) not null,
T_NO
VARCHAR2(3),
ROOM_NO VARCHAR2(3)
)
Create/Recreate primary, unique and foreign key constraints
alter table CLASS
add constraint CLASS_PK primary key (CLASS_NO)
Lab Manual MCSL-45
Page 3
Class
_no
1001
T_no
Room_no
111
1002
112
1003
113
1004
1005
114
115
4
5
Create table
create table PAYSCALE
(
MIN_LIMIT NUMBER,
MAX_LIMIT NUMBER,
GRADE
VARCHAR2(5) not null
)
Create/Recreate primary, unique and foreign key constraints
alter table PAYSCALE
add constraint PAYSCALE_PK primary key (GRADE).
Min_limi
t
Max_limit Grade
Page 4
Number
10
11
60
45
60
34
55
76
c) Display the list of all the teachers who have joined after 10-Jul2009 and whose salary is equal to that of any of the teachers who
joined before 10-Jul-2012.
Ans. Select * from teacher
Page 5
Page 6
Design and implement the suitable relations for the University. Make
and state suitable assumptions.
Ans. Create table Student
STDID VARCHAR2(10) PRIMARY KEY,
NAME VARCHAR2(20),
ADDRESS VARCHAR2(40),
COURSEID VARCHAR2(10),
BATCHID VARCHAR2(10),
CONSTRAINTS STUDENT_FK FOREIGN KEY(COURSEID) REFERENCES
COURSE(COURSEID));
STD_ID
Name
Address
Course
_ID
Batch
_ID
5001
Angad kamat
Dombivali
0001
7001
5002
Shyam Lanke
Thane
0002
7002
5003
Naufil
Siddiqui
Bhiwandi
0003
7003
5004
Sandeep B
Badalapur
0004
7004
5005
Ajinkya
Pune
0005
7005
Page 7
Batch_ID
RC_ID
Course_ID
SDY_ID
Repstd_ID
111
49
101
009
112
50
102
010
113
51
103
011
114
52
104
012
115
53
105
013
Page 8
T_Name
Course_ID
Batch_ID
88001
Asin
001
1111
88002
preeti
002
112
88003
sonal
003
1131
88004
Prinyanka
004
1141
88005
Shruti
005
115
Teacher table
T_ID
T_Name
Batch_ID
101
preeti
1111
102
Niran
112
103
Shruti
113
Page 9
Course Table
Course
_ID
Course_N
ame
Course_f
ees
1001
MBA
10000
10021
MCA
25000
1003
Msc-IT
15000
1004
BBA
7000
R_Name
State
Address
mulund
Mumbai
Pune
Bhopal
M.P
D.k road
each type given in this section 2.2) for the database. Implement
these queries using SQL. Also explain the purpose of each query.
Lab Manual MCSL-45
Page 10
Sanzaya reads;
Ans.
SELECT * FROM SDYCENT WHERE
SDYID=(SELECT SDYID FROM BATCH
WHERE BATCHID=(SELECT BATCHID FROM STUDENT
WHERE UPPER(NAME) LIKE 'SANZAYA%'`
2. Display the course fee where makhunu singh is admitted.
Ans.
BATCHID FROM STUDENT WHERE UPPER(NAME)='MAKHUNU
SINGH'));
3. Display the list of all teachers who take classes for batch B004
Ans. SELECT TNAME FROM TEACHERS WHERE BATCHID='B004';
4. Display the name of teachers who were working in regional
centre BBSR
Ans. SELECT TNAME FROM TEACHERS WHERE BATCHID IN(SELECT
BATCHID
FROM BATCH WHERE RCID=(SELECT RCID FROM
REGCENT WHERE RCNAME='BBSR'));
5. Display the name of teachers who teach in delhi and have atleast
two a in their name.
Ans.
SELECT TNAME FROM TEACHERS WHERE
UPPER(TNAME) LIKE '%A%A%' AND
BATCHID IN(SELECT BATCHID FROM BATCH WHERE
RCID=(SELECT RCID FROM REGCENT WHERE
UPPER(RCNAME)='NDLS'));
Page 11
Page 12
Page 13
Session II
Page 14
Page 15
Page 16
BEGIN OPEN
C1; LOOP
FETCH C1 INTO C_T_NO, C_F_NAME, C_L_NAME,
C_SALARY ; EXIT WHEN NOT C1%FOUND;
UPDATE TEACHER SET SALARY = SALARY * 1.10
WHERE SALARY > 20000; END LOOP;
CLOSE C1;
END;
Page 17
Session III
Page 18
Page 19
FETCHTEN TEACHER%ROWTYPE;
CNT NUMBER :=0;
CURSOR CURR
IS
SELECT * FROM TEACHER;
BEGIN
OPEN CURR;
LOOP
EXIT WHEN CURR%NOTFOUND OR CNT=10;
FETCH CURR INTO FETCHTEN;
DBMS_OUTPUT.PUT_LINE(FETCHTEN.T_NO||' '||
FETCHTEN.F_NAME||' '||FETCHTEN.L_NAME);
CNT :=CNT+1;
END LOOP;
CLOSE CURR;
END;
c) Create a procedure that selects all teachers who get a salary of
Rs.20, 000 and if less than 5 teachers are getting Rs.20, 000 then
give an increment of 5%.
Ans. FETCHTEN TEACHER%ROWTYPE;
CNT NUMBER :=0;
CURSOR CURR
IS
SELECT * FROM TEACHER;
BEGIN
OPEN CURR;
LOOP
EXIT WHEN CURR%NOTFOUND ;
FETCH CURR INTO FETCHTEN;
IF FETCHTEN.SALARY>20000 THEN
DBMS_OUTPUT.PUT_LINE(FETCHTEN.T_NO||' '||
FETCHTEN.F_NAME||' '||FETCHTEN.L_NAME);
ELSE
CNT :=CNT+1;
END IF;
END LOOP;
IF CNT<5 THEN
UPDATE TEACHER SET SALARY=SALARY*1.05 WHERE
SALARY<20000;
DBMS_OUTPUT.PUT_LINE('UPDATED SALARY');
END IF;
Lab Manual MCSL-45
Page 20
Page 21
Page 22
Page 23
Page 24
Trans_D
ate
Jan-08
Feb-08
Dec-07
Mar-08
Deb_Cr
e
debit
credit
credit
credit
Amt
5000
100
1000
20000
Page 25
Pro
ye
s
ye
s
ye
s
ye
s
Page 26
SESSION IV
Page 27
Page 28
Page 29
DECLARE
CURSOR C2 IS
SELECT T_NO,F_NAME, L_NAME, SALARY
FROM TEACHER ;
TEACHER_REC C2%ROWTYPE;
BEGIN
OPEN C2;
FOR TEACHER_REC IN C2
LOOP
I F TEACHER_REC.SALARY > 20000
TEACHER_REC.TITLE = SUPERVISOR;
ENDIF;
END LOOP;
CLOSE C2;
END;
Page 30
Session V
Page 31
Page 32
4) Insert at least 5 new rows in the teacher table and then try to
rollback last 3 rows inserted to the table. (Here, you are required
to use save points).
Ans. create or replace procedure findteacher(teach in varchar2)
is
Lab Manual MCSL-45
Page 33
Page 34
Page 35
Session VI
Page 36
Page 37
Page 38
Page 39
Page 40
Page 41
Session VII
Page 42
2) Create at least two object types in both the University and Bank
database systems. Use these object types in few relations and
enter some data into these relations. Query these databases.
Ans. ED
WROTE FILE AFIEDT.BUF
CREATE TYPE TYPE4UNIV AS OBJECT
(
NAME VARCHAR(20),
PHONE NUMBER(10)
Lab Manual MCSL-45
Page 43
Page 44
Session VIII
1)
Create at least two nested tables for both the University and
Bank database systems. Use these tables and enter some data
into these relations. Query these databases
Ans.
CREATE TYPE ADDRESS_T AS OBJECT (
STREET VARCHAR2(30),
CITY VARCHAR2(20),
STATE CHAR(2),
ZIP CHAR(5) );
/
CREATE TYPE ADDRESS_TAB IS TABLE OF ADDRESS_T;
Lab Manual MCSL-45
Page 45
Session IX
Page 46
Page 47
Page 48
Session X
Page 49
Page 50
Page 51