Ii-Ii DBMS Lab
Ii-Ii DBMS Lab
II Year-II-Semester Regulation:R22
22A0515P -
DATABASE MANAGEMENT SYSTEMS
LAB MANUAL
Submitted By
DVH VENUKUMAR
Asst.Professor
Department of CSE., GIST
Institute Vision and Mission Vision
To emerge as a leading Engineering institution imparting quality education
Mission
IM1 Implement Effective teaching-learning strategies for quality education
IM2 Build Congenial academic ambience for progressive learning
IM3 Facilitate Skill development through Industry-Institute initiatives
IM4 Groom environmentally conscious and socially responsible technocrats
PO5.
Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern
engineering and IT tools including prediction and modeling to complex engineering activities with an
understanding of the limitations.
PO6.
The engineer and society: Apply reasoning informed by the contextual knowledge to assess societal,
health, safety, legal and cultural issues and the consequent responsibilities relevant to the professional
engineering practice.
PO7.
Environment and sustainability: Understand the impact of the professional engineering solutions in
societal and environmental contexts, and demonstrate the knowledge of, and need for sustainable
development.
PO8.
Ethics: Apply ethical principles and commit to professional ethics and responsibilities and norms of
the engineering practice.
PO9.
Individual and team work: Function effectively as an individual, and as a member or leader in diverse
teams, and in multidisciplinary settings.
PO10.
Communication: Communicate effectively on complex engineering activities with the engineering
community and with society at large, such as, being able to comprehend and write effective reports
and design documentation, make effective presentations, and give and receive clear instructions.
PO11.
Project management and finance: Demonstrate knowledge and understanding of the engineering
and management principles and apply these to one’s own work, as a member and leader in a team, to
manage projects and in multidisciplinary environments.
PO12.
Life-long learning: Recognize the need for, and have the preparation and ability to engage in
independent and life-long learning in the broadest context of technological change.
GEETHANJALI INSTITUTE OF SCIENCE & TECHNOLOGY
USHODAYA EDUCATIONAL SOCIETY
An ISO 9001:2015 certified Institution: Recognized under Sec. 2(f)& 12(B) of UGC Act, 1956
3rd Mile, Bombay Highway, Gangavaram (V), Kovur(M), SPSR Nellore (Dt), Andhra Pradesh, India- 524137
Ph. No. 08622-212769, E-Mail: [email protected], Website: www.gist.edu.in
REGULATION-R22-II-YEAR-II-SEMESTER
DEPARTMENT OF CSE
Common All (AI&ML, CS&DS, CSE)
COURSE B.Tech
YEAR II
SEMESTER II
REGULATION RG22
COURSE CODE
CREDITS
ROLLNO OF STUDENT
SECTION
Text Books:
1. Raghu Ramakrishnan, Johannes Gehrke, Jeff Derstadt, Scott Selikoff and Lin Zhu,DatabaseManagement
Systems solutions manual, third Edition, 2013.
GEETHANJALI INSTITUTE OF SCIENCE & TECHNOLOGY
USHODAYA EDUCATIONAL SOCIETY
An ISO 9001:2015 certified Institution: Recognized under Sec. 2(f)& 12(B) of UGC Act, 1956
3rd Mile, Bombay Highway, Gangavaram (V), Kovur(M), SPSR Nellore (Dt), Andhra Pradesh, India- 524137
Ph. No. 08622-212769, E-Mail: [email protected], Website: www.gist.edu.in
REGULATION-R22-II-YEAR-II-SEMESTER
LIST OF PROGRAMS
Program Title of the Program Date Signature
No of the
Faculty
ER Model
1 ER Diagram for Library management Systems
2 ER Diagram for Hospital management Systems
SQL
3 Perform Basic SQL Queries
4 Aggregate Functions
5 View Creation
6 Joins on tables
PL / SQL
7 Multiplication Table
8 Biggest Number
9 Swapping Number
10 Prime Number
11 Sum of Even and Odd Numbers
12 Strong Number
13 Armstrong Number
14 Number Palindrome
15 Factorial Number
16 Fibonacci Series
17 Procedure Creation
Book Entity : It has authno, isbn number, title, edition, category, price.
ISBN is the Primary Key for Book Entity.
Reader Entity : It has UserId, Email, address, phone no, name. Name is
composite attribute of firstname and lastname. Phone no is multi valued
attribute. UserId is the Primary Key for Readers entity.
Staff Entity : It has name and staff_id with staff_id as Primary Key.
A reader can reserve N books but one book can be reserved by only one
reader. The relationship 1:N.
A publisher can publish many books but a book is published by only one
publisher. The relationship 1:N.
Aim:- Draw the ER Diagram for Hospital management System, with the following
entities
1) Patient
2) Room
3) Nurse
4) Employee
5) Doctor :(Trainee, Visiting, Permanent)
6) Receptionist
7) Record
8) Treatment
9) Medicine
PERFORM BASIC SQL QUERIES
Aim:- To Perform basic SQL Queries such as Create, Alter, Insert, Select, Drop & Primary
Key, Check Constraints.
1 ROW CREATED.
SQL> / (For Insert Multiple Records)
EMPNO ENAME
---------- --------------------
100 VARSHA
102 KRISHNA
104 ANUSHA
101 RAMESH
103 KARISHMA
105 VENU
SQL> SELECT DEPTNO,SUM(SAL) FROM EMP1 GROUP BY DEPTNO;
DEPTNO SUM(SAL)
---------- ----------
10 43000
20 40000
VIEW CREATION
Aim:- To create a view to get Department wise total salaries in the “Employee” table.
Table Structure:- EMP1
Field Name Data type
Empno Number(5)
Ename Varchar2(20)
Job Varchar2(15)
Sal Number(10,2)
Deptno Number(5)
CREATING VIEW
OUTER JOIN
SQL> select empno,ename,dept.deptno,dname from emp,dept where
emp.deptno(+)=dept.deptno;
EMPNO ENAME DEPTNO DNAME
---------- --------------- ---------- --------------------
100 LAKSHMI 10 ACCOUNTS
102 RAMESH 10 ACCOUNTS
101 RAVI 20 COMPUTERS
103 MADHURI 20 COMPUTERS
104 MBABU 20 COMPUTERS
30 SALES
SELF JOIN
SQL> select a.ename "employee", b.ename "manager" from emp a, emp b
where a.mgr=b.empno;
EMPLOYEE MANAGER
-------------------- --------------
LAKSHMI MBABU
RAVI MADHURI
RAMESH LAKSHMI
MADHURI RAVI
MBABU RAVI
MULTIPLICATION TABLE
Aim:- To write a PL/SQL program to generate Multiplication table
Algorithm:-
1. Start
2. Declare the variable n
3. Read a number n
4. i1
5. if(i<=10) then
5.1. Print n “*” I “=” n*i
5.2. ii+1
5.3. Goto Step 5
6. Stop
PL/SQL PROGRAM
declare
n number(5);
begin
n:=&n;
for i in 1..10
loop
dbms_output.put_line(n||' * '||i||' = '|| n*i) ;
end loop;
end;
BIGGEST NUMBER
SWAPPING NUMBER
declare
num1 number;
num2 number;
temp number;
begin
num1:=&num1;
num2:=&num2;
end;
INPUT & OUTPUT
Before Swap
num1 = 15 num2 = 20
After Swap
num1 = 20 num2 = 15
PRIME NUMBER
Aim:- To write a PL/SQL program to find given number is prime number or not
Algorithm:-
1. Start
2. Declare variables n,i ,temp
3. Read n
4. For i=2 to n/2
5. If n mod i=0
5.1 temp=0
6. If temp=1
6.1 print Given number is prime
7. else
7.1 print Given number is not prime
8. Stop
PL/SQL PROGRAM
begin
n := &n;
for i in 2..n/2
loop
if mod(n, i) = 0 then
temp := 0;
exit;
end if;
end loop;
if temp = 1 then
dbms_output.put_line('GIVEN NUMBER IS PRIME NUMBER');
else
dbms_output.put_line('GIVEN NUMBER IS NOT PRIME NUMBER');
end if;
end;
INPUT & OUTPUT
Aim:- To write a PL/SQL program to display sum of even and sum of odd numbers
in the given range.
Algorithm:-
1. Start
2. Declare variables n, s1, s2
3. Read a number n
4. s10
5. s20
6. i1
7. if (i<=n) then
7.1. if (mod (i,2)=0) then
7.1.1. s1s1+i
7.2. else then
7.2.1. s2s2+i
7.3. ii+1
7.4. goto step 7
8. print “SUM OF EVEN NUMBERS=”
9. print s1
10. print “SUM OF ODD NUMBERS=”
11. print s2
12. stop
PL/SQL PROGRAM:-
declare
n number(5);
s1 number(5):=0;
s2 number(5):=0;
begin
n:=&n;
for i in 1..n
loop
if(mod(i,2) = 0) then
s1:=s1+i;
else
s2:=s2+i;
end if;
end loop;
dbms_output.put_line('SUM OF EVEN NUMBERS='||s1);
dbms_output.put_line('SUM OF ODD NUMBERS='||s2);
end;
INPUT & OUTPUT
Aim:- To write a PL/SQL program to check the given number is strong or not
Algorithm:-
1. Start
2. Declare n,rem,m,s
3. Read a number n
4. mn
5. s0
6. if (n != 0) then
6.1 rem mod (n,10)
6.2 s s+rem*rem*rem
6.3 n n/10
6.4 goto step 6
7. if (m=s) then
7.1 print m “IS ARMSTRONG NO”
8. else then
8.1 print m “IS NOT ARMSTRONG NO”
9. Stop
PL/SQL PROGRAM:-
declare
n number(5);
rem number(5);
m number(5);
s number(5):=0;
begin
n:=&n;
m:=n;
while(n!=0)
loop
rem:=mod(n,10);
s:=s+rem*rem*rem;
n:=floor(n/10);
end loop;
if (m=s) then
dbms_output.put_line(m||'IS ARMSTRONG NO');
else
dbms_output.put_line(m||'IS NOT ARMSTRONG NO');
end if;
end;
INPUT & OUTPUT
407 IS ARMSTRONG NO
NUMBER PALINDROME
Aim:- To write a PL/SQL program to check the given number is palindrome or not
Algorithm:-
1. Start
2. Declare n, rem, m, rev
3. Read a number n
4. mn
5. rev0
6. if (n!=0) then
6.1 remmod(n,10)
6.2 revrevv*10+rem
6.3 n<-n/10
6.4 goto step 6
7. if(m=rev) then
7.1 print m “IS PALINDROME NO”
8. else then
8.1 print m “IS NOT PALINDROME NO”
9. Stop
PL/SQL PROGRAM
declare
n number(5);
rem number(5);
m number(5);
rev number(5):=0;
begin
n:=&n;
m:=n;
while(n!=0)
loop
rem:=mod(n,10);
rev:=rev*10+rem;
n:=floor(n/10);
end loop;
if (m=rev) then
dbms_output.put_line(m||' is palindrome no');
else
dbms_output.put_line(m||' is not palindrome no');
end if;
end;
INPUT & OUTPUT
555 IS PALINDROME NO
FACTORIAL NUMBER
Algorithm:-
1. Start
2. Declare n, fact=1
3. Read a number n
4. While n>0
4.1 fact=n*fact
4.2 n=n-1
5. print fact
6. Stop
PL/SQL PROGRAM
declare
fact number :=1;
n number := &n;
begin
while n > 0 loop
fact:=n*fact;
n:=n-1;
end loop;
dbms_output.put_line(fact);
end;
INPUT & OUTPUT
Enter value for n: 5
120
FIBONACCI SERIES
Aim:- To write a PL/SQL program to generate Fibonacci series upto n
Algorithm:-
1. Start
2. Declare n, f1, f2, temp
3. read a number n
4. f10
5. f21
6. print “FIBONACCI SERIES ARE”
7. print f1, f2
8. i3
9. if (i<=n) then
9.1 temp f1+f2
9.2 print temp
9.3 f1f2
9.4 f2 temp
9.5 goto step 9
10. Stop
PL/SQL PROGRAM
declare
n number(5);
f1 number(5):=0;
f2 number(5):=1;
temp number(5);
begin
n:=&n;
dbms_output.put_line('fibonacci series are');
dbms_output.put_line(f1);
dbms_output.put_line(f2);
for i in 3..n
loop
temp:=f1+f2;
dbms_output.put_line(temp);
f1:=f2;
f2:=temp;
end loop;
end;
INPUT & OUTPUT
ENTER VALUE FOR N: 5
FIBONACCI SERIES ARE 0
1
1
2
3
PROCEDURE CREATION
LENGTH OF STRING1= 4
CONCATENATION= VENUKUMAR
EMPLOYEE PAY SLIP
Aim:- To write a PL/SQL program to calculate Employee pay slip with the following
conditions
i) HRA is 20%of Basic Salary
ii) DA is 10% of Basic Salary
iii) IT is 5% of Basic Salary
iv) Gsal = BSal + HRA + DA
v) Nsal = Gsal – IT
Table Structure:-
Table Structure:- EMPLOYE
Field Name Data type
Empno Number(10)
Ename Varchar2(20)
Bsal Number(10)
Hra Number(10)
Da Number(10)
It Number(10)
Gsal Number(10)
Nsal Number(10)
Algorithm:-
1. Start
2. Repeat Step3 to 8 until end of the file
3. Hra Bsal * 20/100
4. Da Bsal * 10/100
5. It Bsal * 5/100
6. Gsal Bsal + Hra + Da
7. Nsal Gsal – It
8. Update Hra, Da, It, Gsal, Nsal in the Employe table
TABLE CREATION
SQL> CREATE TABLE EMPLOYE(EMPNO NUMBER(10) PRIMARY KEY,
ENAME VARCHAR2(20), BSAL NUMBER(10), HRA NUMBER(10),
DA NUMBER(10), IT NUMBER(10), GSAL NUMBER(10), NSAL NUMBER(10));
OUTPUT:-
Table Structure:-
Table Structure:- ELECT
Field Name Data type
Mno Number(10)
Cname Varchar(10)
Cur_read Number(5)
Prev_read Number(5)
Amount Number(10,3)
Sar_tax Number(5)
Net_amt Number(6)
Conditions:-
i) If No units are more then 300 then unit rate is Rs. 5.50
ii) If No units are more then 200 then unit rate is Rs. 4.75
iii) If No units are more then 100 then unit rate is Rs. 3.05
iv) If No units are more then 50 then unit rate is Rs. 2.80
v) If No units are less then 50 then unit rate is Rs. 1.45
Algorithm:-
1. Start
2. Repeat step3 to step 12 until the end of loop
3. No_units Cur_read – Prev_read
4. If No_units > 300 then
4.1 Rate 5.50
5. Else if No_units >200 then
5.1 Rate 4.75
6. Else if No_units >100 then
6.1 Rate 3.05
7. Else if No_units > 50 then
7.1 Rate 2.80
8. Else
8.1 Rate 1.45
9. Amount No_units * rate
10. Sar_tax 20
11. Net_amount Amount + Sar_tax
12. Update No_units, Amount, Sar_tax, Net_amount in the Elect table
13. Stop
TABLE CREATION
SQL> CREATE TABLE ELECT(MNO NUMBER(10),CNAME VARCHAR(10),
CUR_READ NUMBER(5),PREV_READ NUMBER(5), NO_UNITS NUMBER(5),
AMOUNT NUMBER(10,3),SAR_TAX NUMBER(5),NET_AMT NUMBER(6));
TABLE CREATED.
OUTPUT:-
Algorithm:-
1. Start
2. Repeat step3 to step 9 until the end of loop
3. Tot m1+m2+m3
4. A tot/3
5. if (m1>=35 and m2>=35 and m3>=35) then
5.1 Result “PASS”
6. Else
6.1 Result “FAIL”
7. if result = “PASS” then
7.1 if A>=60 then
7.1.1 Grade “FIRST CLASS”
7.2 If A>=50 then
7.2.1 Grade “SECOND CLASS”
7.3 Else then
7.3.1 Grade “THIRD CLASS”
8. else then
8.1 Grade “ *********** ”
9. Update tot, result, grade in the student table
10. Stop
TABLE CREATION
Table Structure:-AUDITS
Field Name Data type
Empno Number(10)
Empname Varchar2(10)
Prev_sal Number(10)
Cur_sal Number(10)
Procedure:-
Table Creation 1:- EMP
SQL> CREATE TABLE EMP(EMPNO NUMBER(10),
EMPNAME VARCHAR2(10), JOB NUMBER(5), SAL NUMBER(5),
DEPTNO NUMBER(5));
TABLE CREATED.
OUTPUT:-
TRIGGER CREATION
Aim:- To Create a trigger on Student table so that the date should not be
manipulated on the Sundays
Table Structure:-
Table Structure:- STU
Field Name Data type
Sno Number(5)
Sname Varchar2(20)
Address Varchar 2(20)
Fee Number(10,2)
Procedure:-
Algorithm:
1. Start
2. Create a trigger “Sun_Trig” on Stu table
3. Declare a
4. a To_CHAR(SYSDATE, ‘DY’)
5. If a= ‘SUN’ then
5.1 Print “SORRY..! TRANSACTIONS ON SUNDAY IS NOT VALID ”
6. Stop
TRIGGER:-
ON SUNDAY INPUT:-
OUTPUT:-
Prepared by
Venukumar DVH
M.Sc.,M.Ed.,M.Tech(CSE)
Asst.Professor., Dept.of CSE., Geethanjali Institute of Science and Technology : Gangavaram : Nellore
Dear !
To fight without a weapon is to step forward with determination! There is time! If you think
miracles happen, your life is dark! Although there is light around you, you see darkness
Submitted By
DVH VENUKUMAR
Asst.Professor
Department of CSE., GIST