PROJRCT
PROJRCT
RALETIONAL SCHEMA:
STUDENT:
FACULTY:
CLASS:
ENROLLED:
SNUM NAME
CREATE TABLE STUDENT INSERT INTO student
VALUES(101,'FRED','SCIENCE','JR',19);
INSERT INTO student VALUES(102,'JENNY','MATHS','JR',18);
INSERT INTO student VALUES(103,'JERRY','HISTORY','SR',21);
INSERT INTO student VALUES(104,'SARA','SCIENCE','SR',22);
INSERT INTO student VALUES(105,'LARA','HISTORY','JR',20);
(SNUM INT,SNAME VARCHAR(15),MAJOR VARCHAR(10),LEVEL1
VARCHAR(10),AGE INT,PRIMARY KEY(SNUM));
SELECT * FROM STUDENT;
STUDENT
2 RAMESH 502
3 PRIYA 501
4 POOJA 503
5 SHIV 503
C1 ONE R1 1
C2 TWO R2 1
C3 THREE R3 5
C4 FOUR R1 3
C5 FIVE R2
2
ENROLLED
SNUM NAME
101 C1
101 C4
102 C2
SNUM NAME
102 C4
103 C3
103 C4
105 C5
QUERRIES
FIND THE NAMES OF ALL JUNIOURS (LEVEL=JR) WHO ARE ENROLLED IN
ACLASS TAUEGHT BY I.JOHN
SELECT S.SNAME FROM STUDENT S,CLASS C, ENROLLED
E,FACULTY F
WHERE F.FNAME='I.JHON' AND S.LEVEL1='JR' AND
S.SNUM=E.SNUM AND C.NAME=E.NAME AND C.FID=F.FID;
//OUT PUT//
sname
FRED
JENNY
2] INSURANCE DATABASE
Consider the insurance database given below.
PERSON (driverid: String, name: String, address: String)
CAR (regno: String, model: String, year: Int)
ACCIDENT (repno: Int, dat: Date, location: String)
OWNS (driverid: String, regno: String)
PARTICIPATED (driverid: String, regno: String, repno: Int, damageamt: Int)
Develop an ER schema by reverse engineering from the above relational
schema.
ER-DIAGRAM
RALETIONAL SCHEMA:
PERSON
DRIVEID DNAME ADDRESS
CAR
REGNO MODEL YEAR
OWNS
DRIVEID REGNO
ACCIDENT
REPNO DAT LOCA_TION
PARTICIPATED
D1 JOHN HUBLI
D2 JACK BELGAUM
D3 FRED DHARAWAD
D4 PRIYA BANGLORE
D5 JESSY HUBLI
C1 BMW 2019
C2 HONDACITY 2019
C3 AUDI 2021
C4 VOLKSWAGEN 2022
C5 AUDI 2022
C6 BMW 2021
C7 JAGUAR 2022
CREATE TABLE OWNS(DRIVEID VARCHAR(10),REGNO VARCHAR(10),FOREIGN
KEY(DRIVEID) REFERENCES PERSON(DRIVEID) ,FOREIGN KEY(REGNO)
REFERENCES CAR(REGNO),PRIMARY KEY(DRIVEID,REGNO));
OWNS
DRIVEID REGNO
D1 C1
D1 C5
D2 C4
D3 C2
D4 C3
D5 C6
D5 C7
CREATE TABLE ACCIDENT(REPNO INT,DAT DATE,LOCA_TION
VARCHAR(10),PRIMARY KEY(REPNO));
1 10-JAN-23 HUBLI
2 15-FEB-24 DHARAWAD
3 10-MAR-23 BANGLORE
4 18-APR-22 MYSORE
5 20-MAY-22 BANGLORE
6 30-JULY-23 HUBLI
CREATE TABLE PARTICIPATED(DRIVEID VARCHAR(10),REGNO
VARCHAR(10),REPNO INT,DMGAMT INT,FOREIGN KEY(DRIVEID) REFERENCES
PERSON(DRIVEID),FOREIGN KEY(REGNO) REFERENCES CAR(REGNO),FOREIGN
KEY(REPNO) REFERENCES ACCIDENT(REPNO),PRIMARY
KEY(DRIVEID,REGNO,REPNO));
D1 C1 1 10000
D2 C4 2 12000
D4 C3 2 10000
D3 C2 3 15000
Querries:
UPDATE PARTICIPATED SET DMGAMT=25000 WHERE REGNO='C1' AND
REPNO=1;
SELECT * FROM PARTICIPATED ;
//OUTPUT//
D1 C1 1 10000
D2 C4 2 12000
D4 C3 2 10000
D3 C2 3 15000
3] Movie Database. Data requirements of movie industry are captured.
Each movie is identified by title and year of release. Each movie has
length in minutes and classified under one genres (like action, horror
etc.). Each movie has a plot outline.
Production companies are identified by name and each has an address. A
production company produces one or more movies.
Actors are identified by id. Other details like name and date of birth of
actors are also stored. Each actor acts in one or more movies. Each actor
has a role in movie.
Directors are identified by id. Other details like name and date of birth of
directors are also stored. A Director can act in a movie (including the one
that he or she may also direct). Each director directs one or more movies.
Each movie has one or more actors and one or more directors and is
produced by a production company.
Draw an ER diagram that captures the preceding information. Identify any
constraints not captured by the ER diagram.
Map the ER model to Relational schema and normalize the relations to
2NF.
Create the tables & insert at least 8 tuples in each relation.
Solve the following queries in SQL:-
List the details of horror movies released in 2012 and directed by more
than 2 directors.
List the details of actors who acted in movies having same titles but
released before 2000 and after 2010.
List the details of production companies producing maximum movies.
List the details of movies where director and actor have same date of
birth.
Retrieve the names of directors directed all the movies produced by
any one production company.
ER-DIAGRAM
RALETIONAL SCHEMA:
ACTOR
DIRECTOR
PRODUCTION
PNAME ADDRESS
MOVIE
ACTSIN
DIRECTOR
PNAME ADDRESS
PARAMOUNT TEXAS
ACCE COLORADO
MARVEL NEWYORK
MARVEL_DC NEWYORK
WARNER B WASHINGTON
DISNEY P CALIFORNIA
SELECT*FROM MOVIE;
MOVIE
YEAR
TITLE GENER LEN PNAME DID
1
PARAMOUN 1001
COARLINE 2012 HORROR 2
T 1
1002
GRAVYARD 2008 HORROR 3 ACCE
2
1003
AVENGERS 1998 ACTION 2 MARVEL
3
ACTION 1004
AVENGERS 2011 3 MARVEL_DC
COM 4
HARRYPOT 1005
2006 FICTION 2 WARNER B
R 5
1006
HARYPOTG 2010 FANTACY 2 DISNEY P
6
1007
AVENGERS 1999 ACTION 2 MARVEL
7
CREATE TABLE ACTSIN(ACTORID INT,TITLE VARCHAR(20),YEAR1 INT,PRIMARY
KEY(ACTORID,TITLE),FOREIGN KEY(ACTORID) REFERENCES
ACTOR1(ACTORID),FOREIGN KEY(TITLE,YEAR1) REFERENCES
MOVIE(TITLE,YEAR1));
Querries:
SELECT * FROM MOVIE WHERE YEAR1=2012 AND GENER='HORROR';
//OUT PUT//
YEAR LE
TITLE GENER PNAME DID
1 N
//OUTPUT//
ACTORID NAME DOB
//output//
NAME
JOHN A
CHRIS B
DAXON C
PAISLEY M
BROOKLYN D
RACHEL V
NAME
PHOEBE B
//output//
PNAME COUNT(PNAME)
MARVEL 2
Bank Database.
Address and phone for each bank are also stored. Each branch is identified by its
bank. Branch has name address and phone. A customer can open different kinds of
accounts with the branches. An account can belong to more than one customer.
Customers are identified by their SSN, name, address and phone number. There are
different types of loans, each identified by a loan number. A customer can take more
than one type of loan and a loan can be given to more than one customer. Loans
have a duration and interest rate. Make suitable assumptions and use them in
showing maximum and minimum cardinality ratios.
1. Draw an ER diagram that captures the preceding information. Identify any
constraints not captured by the ER diagram.
2. Map the ER model to Relational schema and normalize the relations to 2NF.
3. Create the tables & insert at least 8 tuples in each relation.
4. Solve the following queries in SQL:
a. List the details of customers who have joint account and also have at least one
loan.
b. List the details of the branch that has given the maximum loan.
c. List the details of savings accounts opened in the SBI branches located at
Bangalore d. List the name of branch along with its bank name and total amount of
loan
given by it.
e. Retrieve the names of customers who have accounts in all the branches
ER-DIAGRAM
Relational Schema:
BANK
BRANCH
ACCOUNT
ACCNO TYPE ADDR NAME
CUSTOMER
L DURATIO
AMT LTYPE RATE ADDR NAM
NO N
LOAN
CUST_ACC
ACCNO SSN
CUST_LOAN
LNO SSN
BRANCH 1
ACCOUNT 1
ACCN
TYPE ADDR NAME
O
12877 SAVINGS BANGLORE SBI
CURREN
13838 SAINAGAR UNION
T
GANDHINAGA
49444 SAVINGS ICICI
R
CURREN
34944 DADAR PNB
T
12873 SAVINGS KCD KVGB
CURREN
12872 KUD VIJAY
T
CURREN
12233 BADLAPUR BOB
T
34877 SAVINGS MIRZAPUR CANARA
CUSTOMER 1
SS
CNAME CADDR PNO
N
75496
1 ALEX HUBLI
7
23545
2 JOHN DHARAWAD
5
75496
3 PRASANNA BANGLORE
2
75496
4 SAM HAVERI
1
75494
5 HOBS HUBLI
5
45678
6 PRAVEEN BANGLORE
7
75495
7 ANAND KITTUR
4
75499
8 ABHAY BADLAPUR
8
LOAN 1
L DURATIO
AMT LTYPE RATE ADDR NAME
NO N
1000
11 2 EDUCATION 10 BANGLORE SBI
0
1200
12 3 VEHICLE 12 SAINAGAR UNION
0
2000
13 2 HOME 15 DADAR PNB
0
3000
14 1 EDUCATION 8 BANGLORE SBI
0
5000
15 4 HOME 12 KCD KVGB
0
2000
16 3 MEDICAL 11 KUD VIJAY
0
4000
17 3 HOME 17 BADLAPUR BOB
0
8000
18 5 EDUCATION 9 BANGLORE SBI
0
CREATE TABLE CUST_ACC(ACCNO INT,SSN INT,FOREIGN KEY(ACCNO) REFERENCES
ACCOUNT(ACCNO),FOREIGN KEY(SSN) REFERENCES CUSTOMER (SSN),PRIMARY
KEY(ACCNO,SSN));
INSERT INTO CUST_ACC VALUES(12877,1);
ACCNO SSN
12877 1
49444 2
34944 3
12873 2
12873 4
12233 5
34877 6
34877 7
CREATE TABLE CUST_LOAN(LNO INT,SSN INT,FOREIGN KEY(LNO) REFERENCES LOAN(LNO),
FOREIGN KEY(SSN) REFERENCES CUSTOMER (SSN),PRIMARY KEY(LNO,SSN));
LNO SSN
11 1
12 2
15 3
14 2
13 4
18 5
17 6
17 7
1. List the details of customers who have joint account and also have at least one
loan.
SELECT DISTINCT C.SSN,C.CNAME,C.CADDR,C.PNO
Output
SSN CNAME CADDR PNO
2. List the name of branch along with its bank name and total amount of loan given
by it.
SELECT B.NAME,B.ADDR,L.AMT
GROUP BY B.NAME,B.ADDR,L.AMT
Output
NAME ADDR AMT
3. List the details of savings accounts opened in the SBI branches located at
Bangalore
SELECT A.*
FROM ACCOUNT A,BRANCH B
WHERE A.ADDR=B.ADDR AND B.NAME="SBI" AND B.ADDR="BANGLORE";
Output
ACCNO TYPE ADDR NAME
4. Retrieve the names of customers who have accounts in all the branches at
specific location.
SELECT C.CNAME
ALEX
5.List the details of the branch that has given the maximum loan.
SELECT B.*,MAX(L.AMT)
FROM BRANCH B,LOAN L,CUST_LOAN C
WHERE B.ADDR=L.ADDR AND L.LNO=C.LNO AND B.NAME=L.NAME ;
Output
ADDR NAME PHONE MAX(L.AMT)
ER-DIAGRAM
Relational Schema:
DOCTOR 1
DSSN DNAME SPECIALITY YRS_EXP
PATIENT 1
PSS
PNAME ADDRESS AGE DSSN
N
PH_COMPANY 1
CNAME PHONE
PHARMACY 1
PH_NAME PH_ADDRESS PH_PHONE
DRUG 1
TRADE_NAME CNAME FORMULA
SELLS 1
PH_NAME TRADE_NAME PRICE
CONTRACTS 1
PH_NAME CNAME S_SSN S_DATE E_DATE
PRESCRIBES 1
DSSN PSSN TRADE_NAME QUANTITY P_DATE
1 Sujatha Heart 5
2 Rashmi GeneralMedicine 4
3 Sneha Neuro 10
4 Sagar Dentist 8
5 Rohit Psychologist 7
11 Banashree Badami 22 1
12 Laxmi Belgaum 22 2
13 Vyshnavi Hubli 22 3
14 Ramesh Arabhavi 22 4
15 Aravind Gattaprabha 22 5
CNAME PHONE
APOLLO 12345
MEDPLUS 88888
NAVYALABS 22222
KIMS 77777
DRUG 1
TRADE_NAME CNAME FORMULA
IMMUNOSU
HEARTAB APOLLO
P
IMMUNOSU
RENAL9 NAVYALABS
P
SUSHRUTH CROCIN 5
ANJALI DOLO650 10
TEJAS ATIVA 30
SIDDHARTH AZITHROMYCIN 25
SIDDHARTH RENAL9 25
ANJALI ORBITOL 25
TEJAS HYPNO8 30
SOUMYA HYPNO8 30
INSERT INTO CONTRACTS 1 VALUES('SUSHRUTH', 'APOLLO', 123,
2020, 2025);
INSERT INTO CONTRACTS 1 VALUES('ANJALI', 'MEDPLUS', 124, 2021,
2026);
INSERT INTO CONTRACTS 1 VALUES('SUSHRUTH', 'NAVYALABS', 125,
2019, 2029);
INSERT INTO CONTRACTS 1 VALUES('ANJALI', 'NAVYALABS', 126,
2021, 2026);
INSERT INTO CONTRACTS 1 VALUES('SOUMYA', 'NAVYALABS', 127,
2018, 2028);
INSERT INTO CONTRACTS 1 VALUES('TEJAS', 'KIMS', 128, 2022, 2027);
INSERT INTO CONTRACTS 1 VALUES('SIDDHARTH', 'NAVYALABS', 129,
2022, 2027);
SELECT * FROM CONTRACTS 1 ;
DELETE FROM CONTRACTS 1;
PH_NAME CNAME S_SSN S_DATE E_DATE
PRESCRIBES 1
DSS PSS
TRADE_NAME QUANTITY P_DATE
N N
2023-
1 11 HEARTAB 20
05-27
DSS PSS
TRADE_NAME QUANTITY P_DATE
N N
2024-
2 12 ORBITOL 10
05-25
2024-
3 13 HYPNO8 30
05-24
2024-
2 13 RENAL9 5
05-25
2024-
4 15 ATIVA 7
05-20
2024-
5 14 AZITHROMYCIN 10
05-22
2024-
1 15 DOLO650 30
05-20
2024-
2 13 CROCIN 10
05-22
//1 For each patient list out the patent's name, patient's
doctor's name & prescription details.
SELECT P.PNAME,
D.DNAME,R.TRADE_NAME,R.QUANTITY,R.P_DATE
FROM DOCTOR D, PATIENT P, PRESCRIBES R
WHERE P.DSSN = D.DSSN AND P.DSSN = R.DSSN ;
Banashr 2023-05-
Sujatha HEARTAB 20
ee 27
Banashr 2024-05-
Sujatha DOLO650 30
ee 20
2024-05-
Laxmi Rashmi ORBITOL 10
25
PNAME DNAME TRADE_NAME QUANTITY P_DATE
2024-05-
Laxmi Rashmi CROCIN 10
22
2024-05-
Laxmi Rashmi RENAL9 5
25
Vyshnav 2024-05-
Sneha HYPNO8 30
i 24
2024-05-
Ramesh Sagar ATIVA 7
20
2024-05-
Aravind Rohit AZITHROMYCIN 10
22
//2 For each pharmacy list but the drugs that it sells,
containing Paracetemol as one of the ingredient in its formula
along with its Pharmaceutical Company.
SELECT S.PH_NAME, S.TRADE_NAME, D.CNAME
FROM SELLS S, DRUG D
WHERE D.FORMULA LIKE 'PARACET' AND S.TRADE_NAME =
D.TRADE_NAME;
//4 For each doctor display the doctor's name and the count
of prescriptions given by doctor containing the drugs made
by NAVYYA LABS.
SELECT D.DNAME, COUNT(P.DSSN)
FROM DOCTOR D, PRESCRIBESP, DRUG T
WHERE D.DSSN = P.DSSN AND P.TRADE_NAME =
T.TRADE_NAME AND T.CNAME LIKE 'NAVYALABS'
GROUPBY P.DSSN, D.DNAME;
DNAME COUNT(P.DSSN)
Sagar 1
//5 For each patient display the patient's name, drug name &
the pharmacy name from where the patient bought the drug.