0% found this document useful (0 votes)
16 views

Dbms Lab Exp4

Uploaded by

sumitashetty19
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Dbms Lab Exp4

Uploaded by

sumitashetty19
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

DBMS LAB with Mini Project(21CSL55) 2023

Program - 4
Aim: Introduce concepts of PLSQL and usage on the table.
Program: Program: Consider the schema for College Database:
STUDENT(USN, SName, Address, Phone, Gender)
SEMSEC(SSID, Sem, Sec)
CLASS(USN, SSID)
COURSE(Subcode, Title, Sem, Credits)
IAMARKS(USN, Subcode, SSID, Test1, Test2, Test3, FinalIA)
Write SQL queries to
i. List all the student details studying in fourth semester ‘C’ section.
ii. Compute the total number of male and female students in each semester and in each
section.
iii. Create a view of Test1 marks of student USN ‘1BI15CS101’ in all Courses.
iv. Calculate the FinalIA (average of best two test marks) and update the corresponding table
for all students.
v. Categorize students based on the following criterion:
If FinalIA = 17 to 20 then CAT = ‘Outstanding’
If FinalIA = 12 to 16 then CAT = ‘Average’
If FinalIA< 12 then CAT = ‘Weak’
Give these details only for 8th semester A, B, and C section students.
Schema Diagram:

Artificial Intelligence and Data Science Engineering AY: 2023-24 Page 1


DBMS LAB with Mini Project(21CSL55) 2023

(i) Query for creating table student:


create table student (
usn varchar(10),
sname varchar(15),
address varchar(15),
phone int,
gender varchar(6),
primary key(usn));
Output

(ii) Query for creating table semsec:


create table semsec (
ssid varchar(5),
sem int,
sec varchar(5),
primary key(ssid) );
Output

(iii) Query for creating table class:


create table class (
usn varchar(10),
ssid varchar(5),
primary key(usn),
foreign key(usn) references student(usn) on delete cascade,
foreign key(ssid) references semsec(ssid) on delete cascade );

Artificial Intelligence and Data Science Engineering AY: 2023-24 Page 2


DBMS LAB with Mini Project(21CSL55) 2023

Output

(iv) Query for creating table course:


create table course (
subcode varchar(8),
title varchar(15),
sem int,
credits int,
primary key(subcode) );
Output

(v) Query for creating table IAmarks:


create table IAmarks (
usn varchar(10),
subcode varchar(8),
ssid varchar(5),
test1 int,
test2 int,
test3 int,
finalIA int,
primary key(usn,subcode,ssid),
foreign key(usn) references student(usn) on delete cascade,
foreign key(subcode) references course (subcode),
foreign key(ssid) references semsec(ssid) );

Artificial Intelligence and Data Science Engineering AY: 2023-24 Page 3


DBMS LAB with Mini Project(21CSL55) 2023

Output

(i)Queries for inserting table STUDENT:


insert into STUDENT values('CS101','Arun','ujire','9481235681','Male');
insert into STUDENT values('CS102','Pramya','Mangalore','8945689532','Female');
insert into STUDENT values('CS103','Ravi','Bangalore','9568742361','Male');
insert into STUDENT values('CS104','Vani','Puttur','8945623145','Female');
insert into STUDENT values('CS105','Akshatha','Bantwal','9845632147','Female');
insert into STUDENT values('CS106','Ranjan','Karwar','9485632158','Male');
Sample Output
Select * from student;
(ii)Queries for inserting table SEMSEC:
insert into SEMSEC values('CS4A','4','A');
insert into SEMSEC values('CS4B','4','B');
insert into SEMSEC values('CS4C','4','C');
insert into SEMSEC values('CS8A','8','A');
insert into SEMSEC values('CS8B','8','B');
insert into SEMSEC values('CS8C','8','C');
Sample Output
Select * from SEMSEC;
(iii) Queries for inserting table CLASS:
insert into CLASS values('CS101','CS8A');
insert into CLASS values('CS102','CS8A');
insert into CLASS values('CS103','CS8B');
insert into CLASS values('CS104','CS8C');
insert into CLASS values('CS105','CS4C');
insert into CLASS values('CS106','CS4C');
Sample Output

Artificial Intelligence and Data Science Engineering AY: 2023-24 Page 4


DBMS LAB with Mini Project(21CSL55) 2023

Select * from CLASS;

(iv) Queries for inserting table COURSE:


insert into COURSE values('15CS41','ACA','4','5 ');
insert into COURSE values('15CS42 ','GTE','4','4');
insert into COURSE values('15CS43','C++','4','3');
insert into COURSE values('10CS81','JAVA','8','4');
insert into COURSE values('10CS82','WEB','8','4');
insert into COURSE values('10CS83','IOT','8','5');
Sample Output
Select * from COURSE;
(v) Queries for inserting table IAmarks:
insert into IAmarks values('CS101','10CS81','CS8A','19','20','18','');
insert into IAmarks values('CS102','10CS81','CS8A','16','15','12','');
insert into IAmarks values('CS103','10CS82','CS8B','09','08','12','');
insert into IAmarks values('CS104','10CS83','CS8C','03','05','08','');
insert into IAmarks values('CS105','15CS41','CS4C','10','14','16','');
insert into IAmarks values('CS106','15CS43','CS4C','13','15','20','');
Sample Output
select * from iamarks;
(i)Write SQL queries to list all the student details studying in fourth semester ‘C’ section.
Query: select s.usn,sname,gender,address,phone ,sc.sem,sc.sec from
STUDENT s,SEMSEC sc,CLASS c
where s.usn=c.usn and c.ssid=sc.ssid and sc.sem=8 and sc.sec=’C’;
Output:

(ii)Write SQL queries to compute the total number of male and female students in each
semester and in each section .
Query: select sem,sec,gender,count(*) as count from STUDENT s, SEMSEC sc, CLASS c
where s.usn=c.usn and sc.ssid=c.ssid
group by(sem,sec,gender);
Output:
(iii)Write SQL queries to create a view of Test1 marks of student USN ‘1BI17CS101’ in all
subjects.

Artificial Intelligence and Data Science Engineering AY: 2023-24 Page 5


DBMS LAB with Mini Project(21CSL55) 2023

Query: create view test1 as ( select usn,test1,subcode from iamarks where usn=’CS101’ );
select * from test1;
Output:
(iv)Write SQL queries to calculate the FinalIA (average of best two test marks) and update
the corresponding table for all students.
Query(a): create view average_finder1 as (select usn,subcode,greatest(test1,test2,test3) as
highest, case when test1<greatest(test1,test2,test3) and test1>least(test1,test2,test3)
then test1 when test2<greatest(test1,test2,test3) and test2>least(test1,test2,test3)
then test2 else test3 end as second_highest from iamarks );
Output:
select * from average_finder1;
Query(b): update IAMARKS a set finalia = ( select (highest+second_highest)/2 from
average_finder1 where a.usn =usn and a.subcode= subcode);
Output:
select * from iamarks;
(v) Categorize students based on the following criterion:
If FinalIA = 17 to 20 then CAT = ‘Outstanding’
If FinalIA = 12 to 16 then CAT = ‘Average’
If FinalIA< 12 then CAT = ‘Weak’
Give these details only for 8th semester A, B, and C section students.
Query: select s.usn,s.sname,s.address,s.phone,s.gender,
(case when ia.finalia between 17 and 20 then 'outstanding'
when ia.finalia between 12 and 16 then 'average'
else 'weak' end) as CATEGORY
from student s, semsec ss, iamarks ia, course c
where s.usn = ia.usn and ss.ssid = ia.ssid and c.subcode = ia.subcode and c.sem = 8;
Output:

Artificial Intelligence and Data Science Engineering AY: 2023-24 Page 6

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy