Database4 CollegeDatabase
Database4 CollegeDatabase
Database4 CollegeDatabase
College Database
STUDENT(USN, Sname, Address, Phone, Gender)
SEMSEC(SSID, Sem, Sec)
CLASS (USN, SSID)
SUBJECT(Subcode, Title, Sem, Credits)
IAMARKS (USN, Subcode, SSID,Test1,Test2,Test3,FinalIA)
ER Diagram for College Database
Schema Diagram
Table Creation
create table student create table semsec
( (
usn varchar(10), ssid varchar(5),
sname varchar(10), sem int,
address varchar(10), sec varchar(5),
phone bigint, primary key(ssid)
gender char(1), );
primary key(usn)
);
insert into student values('CS101','Arun',‘Ujire','9481235681','M');
insert into student values('CS102','Pramya','Mangalore','8945689532','F');
insert into student values('CS103','Ravi','Bangalore','9568742361','M');
insert into student values('CS104','Ravi','Bangalore','9568742361','M');
insert into student values('CS105','Akshatha','Bantwal','9845632147','F');
insert into student values('CS106','Ranjan','Karwar','9485632158','M');
insert into semsec values('CS4A', 4, 'A');
insert into semsec values('CS5B', 5, 'B');
insert into semsec values('CS5C', 5, 'C');
insert into semsec values('CS7A', 7 , 'A');
insert into semsec values('CS7B', 7 , 'B');
insert into semsec values('CS3C', 3, 'C');
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
);
create table subject
(
subcode varchar(8),
title varchar(15),
sem int,
credits int,
primary key(subcode)
);
insert into class values('CS101','CS7A');
insert into class values('CS102','CS7A');
insert into class values('CS103','CS7B');
insert into class values('CS104','CS7C');
insert into class values('CS105','CS3C');
insert into class values('CS106','CS3C');
1 CASE
2 WHEN ComparsionCondition THEN result
3 WHEN ComparsionCondition THEN result
4 ELSE other
5
END
Example:
Select EmployeeName,
CASE
WHEN Salary >=80000 AND Salary <=100000 THEN 'Director'
WHEN Salary >=50000 AND Salary <80000 THEN 'Senior Consultant'
Else ‘consultant'
END AS Designation
from Employee
4. Calculate the FinalIA (average of best two test marks) and update the
corresponding table for all students.
create view best_two_finder 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 secondhighest from iamarks
);