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

Table: PATIENT Table: DOCTOR Pname Age Ward Admitdate Tariff Sex Ward Dname

1. Differentiates between candidate key and primary key with an example. Provides SQL commands to list information from tables PATIENT and DOCTOR based on various criteria like ward, date range, grouping, aggregation etc. 2. Mentions two preconditions for union of relations. Differentiates between selection and projection. Provides SQL queries on tables SUPPLIER and STORE to display, filter, sort and aggregate data based on various conditions. 3. Differentiates between DDL and DML commands, and cardinality and degree. Provides SQL queries on tables STUDENT and CLTEACHER to display, filter, sort, add columns and perform aggregation based on various criteria.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
155 views

Table: PATIENT Table: DOCTOR Pname Age Ward Admitdate Tariff Sex Ward Dname

1. Differentiates between candidate key and primary key with an example. Provides SQL commands to list information from tables PATIENT and DOCTOR based on various criteria like ward, date range, grouping, aggregation etc. 2. Mentions two preconditions for union of relations. Differentiates between selection and projection. Provides SQL queries on tables SUPPLIER and STORE to display, filter, sort and aggregate data based on various conditions. 3. Differentiates between DDL and DML commands, and cardinality and degree. Provides SQL queries on tables STUDENT and CLTEACHER to display, filter, sort, add columns and perform aggregation based on various criteria.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

1. a) Differentiate between Candidate key and Primary key with suitable example.

Write SQL commands for b) to g) on the basis of tables PATIENT and DOCTOR
Table: PATIENT Table: DOCTOR
PNAME AGE WARD ADMITDATE TARIFF SEX WARD DNAME
KAREEM 32 ORTHO 2012-02-19 600 M ENT KAPIL GUPTA
ARUN 12 SURGERY 2012-11-01 900 M ORTHO AMARJIT BEDI
ZAFAR 30 ENT 2012-01-12 750 M SURGERY PRADIP JAIN
KIRAN 16 ENT 2012-02-24 750 F CARDIO NIRMAL SINHA
ANKITA 29 CARDIO 2012-02-20 800 F
SUHAIL 45 ORTHO 2012-02-22 600 F
KETAN 19 CARDIO 2012-01-13 800 M
SHILPA 23 SURGERY 2012-02-21 900 F
ARPRIT 42 CARDIO 2012-02-23 800 M
TARUN 53 SURGERY 2012-01-17 900 M
b) List the complete information of all male patients in SURGERY ward from PATIENT table
c) Increase the TARIFF (daily charge) of ORTHO ward by 15%.
d) Display a report showing PNAME, AGE, WARD and weekly TARIFF
e) Add 'JULIAN', 24, 'CARDIO', '2012-05-29', 800, 'M' in the PATIENT table
f) Count the number of patients in each ward
g) Give the output of the following SQL commands:
i) SELECT SEX, COUNT(SEX) FROM PATIENT GROUP BY SEX;
ii) SELECT MAX(ADMITDATE), MIN(ADMITDATE) FROM PATIENT;
iii) SELECT SUM(TARIIF), AVG(TARIFF) FROM PATIENT
WHERE WARD IN ('CARDIO', 'ORTHO');
iv) SELECT PNAME, DNAME FROM PATIENT P, DOCTOR D
WHERE P.WARD=D.WARD AND P.WARD='ENT';

2. a) i) Mention two preconditions for Union of two relations.


ii) Differentiate between Selection and Projection with respect to database relation.

Answer SQL questions b) to h) on the basis of tables SUPPLIER and STORE given below.
Table: SUPPLIER Table: STORE
SNO NAME AREA ITEM PRICE SNO
S01 COMPUTER MART CHADNI CHOWK MOTHER BOARD 15000 S01
S02 COMPUTER POINT RAJEEV CHOWK HARD DISK 5000 S01
S03 HARDWARE HOME NEHRU PLACE KEYBOARD 600 S02
S05 TECHNO SHOP KAMLA NAGAR MOUSE 250 S01
MOTHER BOARD 16000 S02
KEY BOARD 500 S03
LED MONITOR 6000 S04
LED MONITOR 5000 S05
MOUSE 500 S05
HARD DISK 4500 S03
b) Display ITEM and PRICE from STORE in the ascending order of their PRICE
c) Display the SNO and NAME from SUPPLIER located in RAJEEV CHOWK
d) Display the minimum and maximum PRICE of each ITEM from the table STORE
e) Display the details of ITEMs whose PRICE is in the range 1000 to 3000 using table the SRORE
f) Display the ITEM, PRICE and NAME using tables STORE and SUPPLIER
g) Increase the PRICE of each ITEM by 50 whose SNO is either 'S01' or 'S03'
h1) SELECT DISTINCT ITEM FROM SRORE WHERE PRICE>=5000;
h2) SELECT SNO, COUNT(*) FROM STORE GROUP BY SNO HAVING COUNT(*)>1;
h3) SELECT PRICE, AREA FROM STORE X, SUPPLIER Y
WHERE X.SNO=Y.SNO AND ITEM IN ('HARD DISK', 'MOUSE');
h4)SELECT ITEM, 0.05*PRICE DISCOUNT FROM STORE WHERE SNO='S05';
Page 1 of 4
3. a) Differentiate between
i) DDL and DML commands of SQL ii) Cardinality and Degree

Answer SQL questions b) to g) on the basis of tables STUDENT and CLTEACHER


Table: STUDENT Table: CLTEACHER
SNAME CLA TH PR GR TNAME CLA
GUATAM 12B 60 30 A1 MS. NEETA 12C
DEEPAK 12A 49 25 B1 MR. DAVID 12A
DILIP 12B 53 28 A2 MS. KIRAN 12B
MOHAN 12B 64 29 A1
SARAH 12A 53 25 B1
KAVITA 12B 53 23 B1
IQBAL 12A 62 30 A1
ARIJIT 12B 55 28 A2
GAUTAM 12A 58 30 A2
MOHAN 12A 67 29 A1
b) Display details of student when CLA is '12A'
c) Display the table sorted on CLA and then on SNAME
d) Display details of all the students when TH>60 AND PR>28
e) Display number of students CLA-wise
f) Add a column TTOT in the student table to store TH+PR
g) Give the output of the following SQL command:
i) SELECT MAX(TH+PR), MIN(TH+PR) FROM STUDENT WHERE CLA='12B';
ii) SELECT GR, COUNT(GR) FROM STUDENT WHERE GR!='B1' GROUP BY GR;
iii) SELECT COUNT(DISTINCT SNAME), COUNT(SNAME) FROM STUDENT;
iv) SELECT SNAME, TNAME FROM STUDENT S, CLTEACHER C
WHERE S.CLA=C.CLA AND SNAME LIKE 'D%';

4. a) Differentiate between SQL commands


i) UPDATE and ALTER TABLE ii) DELETE and DROP TABLE
Answer SQL questions based on tables EMPLOYEE and SALARY
Table: EMPLOYEE Table: SALARY
ID NAME DEPART SEX EXP ID BASIC HRA DA
101 JOHN HRD M 12 101 90000 22500 76500
104 PETER MKT M 15 104 80000 20000 68000
107 GEORGE ICT M 10 107 85000 21250 72250
114 MARY HRD F 13 114 88000 22000 74800
109 PAULA ICT F 19 109 92000 23000 78200
105 ALEX MKT M 10 105 85000 21250 72250
117 JULIA RND F 13 130 96000 24000 81600
111 MARSHA ICT F 12 111 83000 20750 70550
130 DARREN RND M 15
110 JOHNSON RND M 12
b) i) Display NAME, DEPART of employee whose DEPART is 'HRD' and EXP>15
ii) Display the average GROSS of employee working in 'ICT' DEPART using the tables
EMPLOYEE and SALARY (GROSS is calculated as BASIC+HRA+DA)
iii) Display the minimum HRA of female employee
iv) Increase the DA of every employee by 20%
c) i) SELECT SEX, COUNT(*) FROM EMPLOYEE GROUP BY SEX;
ii) SELECT MIN(BASIC), MAX(HRA) FROM SALARY;
iii) SELECT COUNT(DEPART), COUNT(DISTINCT DEPART) FROM EMPLOYEE;
iv) SELECT NAME, BASIC FROM EMPLOYEE E, SALARY S
WHERE DEPART='MKT' AND E.ID=S.ID;
Page 2 of 4
5. a) Consider the EMPLYOEE table given be:
CODE EMPNAME JOINDATE BASIC
1045 KARAN JAIN 2010-07-02 80000
1072 ALEX JOHN 2007-04-09 75000
1032 RITA GUPTA 2010-07-02 80000
What is the degree and the cardinality of the table EMPLOYYE? Two new columns are added and three
new rows are added to table. What is the degree and the cardinality of the table after the changes?
b) Answer the SQL questions based on STUDENT table and SPORTS table:
STUDENT SPORTS
ANO SNAME CLA SEC PHONE ANO GAME CNAME GR
1271 UTPAL 12 C 66991234 1324 FOOTBALL GAUTAM A
1324 DINESH 10 A 99678910 1271 VOLLEYBALL MOHIT B
1364 AKHTAR 12 B 55123430 1434 BASKETBALL INDER B
1434 VARUN 11 B 69235678 1461 FOOTBALL GAUTAM B
1461 DAVID 12 B 93125702 2371 BASKETBALL INDER A
2324 SURESH 11 C 54435729 2385 FOOTBALL GAUTAM A
2371 MOHINI 10 C 63363747 1364 BASKETBALL INDER B
2385 SATISH 12 B 97843782 2324 VOLLEYBALL MOHIT A
i) Display ANO, SNAME, CLA and PHONE who are either in class 10 or in class 12
ii) Display the number of students in each class from the table STUDENT
iii) Display SPORTS table sorted on CNAME
iv) Display details of students who have 'FOOTBLL' as GAME
v) SELECT NAME, CLA FROM STUDENT WHERE NAME LIKE 'D%';
vi) SELECT SNAME, GR FROM STUDENT A, SPORTS B
WHERE A.ANO=B.ANO AND GAME='VOLLEYBALL';
vii) SELECT MAX(GAME), MIN(GAME) FROM SPORTS;
viii) SELECT COUNT(*), GAME FROM SPORTS GROUP BY GAME;

6. a) Differentiate between Candidate key and Alternate key with suitable example.
b) Write SQL commands for the statements i) to iv) and give outputs for SQL queries v) to viii)
Table: SENDER
SID SNAME SADDRESS SCITY
ND01 RAHUL JAIN 2B/16 JANAK PURI NEW DELHI
MU02 HARSH SINHA H12-34 NEW TOWN MUMBAI
MU15 PRADIP JHA 27/A PARK STREET MUMBAI
ND50 TARUN PRASAD 122K VASANT KUNJ NEW DELHI
Table: RECIPIENT
RID SID RNAME RADRESS RCITY
KO05 ND01 RAVI BAJPAYEE 5/24 CENTRAL AVENUE KOLKATA
ND08 MU02 SUNIT MAHAJAN 116-D ANAND VIHAR NEW DELHI
MU19 ND01 HARDIK SINGH 2A-29 ANDHERI EAST MUMBAI
MU32 MU15 PRANAV SWAMY B5/30 BANDRA WEST MUMBAI
ND48 ND50 SANJAY TRIPATHI 13 BL-D, MAYUR VIHAR NEW DELHI
i) Display the names of all SENDERS from MUMBAI
ii) Display the RID, SNAME, SADDRESS, RNAME, RADDRESS of every RECIPIENT
iii) Display Recipient details in ascending order of RNAME
iv) Display number of Recipients from every city
v) SELECT DISTINCT SCITY FROM SENDER;
vi) SELECT A.SNAME, B.RNAME FROM SENDER A, RECIPIENT B
WHERE A.SID=B.SID AND B.RCITY='MUMBAI';
vii) SELECT RNAME, RADDRESS FROM RECIPIENT
WHERE RCITY NOT IN ('MUMBAI', 'KOLKATA');
viii) SELECT RID, RNAME FROM RECIPIENT WHERE SID IN ('MU02', 'ND50');
Page 3 of 4
7. a) Explain Union of two tables using a suitable example.

Answer SQL questions based on tables EVENT and COACH.


Table: EVENT
ECODE EVENTNAME PNUM PRIZE EVENTDATE
E001 RELAY 100X4 16 12000 2004-01-23
E002 HIGH JUMP 10 15000 2003-12-12
E003 SHOT PUT 12 10000 2004-02-14
E005 LONG JUMP 12 11000 2004-01-01
E008 DISCUSS THROW 10 10000 2004-03-19
Table: COACH
PCODE NAME ECODE
C001 AHMAD HUSSAIN A001
C002 RAVINDER CHADDHA A008
C003 JANILA CHERIAN A001
C004 NAAZ MOHD A003
b) i) Display all EVENTNAME with their ECODEs in descending order
ii) Display sum of PRIZE for each of the PNUM of participant groupings
iii) Display the coach's name and ECODEs and sorted on ECODE from the table COACH
iv) Display EVENT table where date earlier than 2004-01-01 and sorted on PNUM
c) i) SELECT COUNT(DISTINCT PNUM) FROM EVENT;
ii) SELECT MAX(EVENTDATE), MIN(EVENTDATE) FROM EVENT;
iii) SELECT SUM(PRIZE) FROM EVENT;
iv) SELECT DISTINCT CCODE FROM COACH;

8. a) Differentiate between WHERE and HAVING clause of SELECT command.

Answer SQL questions based on tables STUDENT and MARKS.


Table: STUDENT Table: MARKS
SNO NAME SEX CLA SNO PHYS CHEM MATH
23 PRAFULLA M 12C 44 45 64 56
25 FARIDA F 12C 30 79 73 75
28 SMRITI F 12C 42 89 94 96
30 VISHAL M 12D 28 74 72 77
31 TRIPTHI F 12D 25 59 57 62
33 GEETA F 12D 38 68 66 71
35 PAWAN M 12C 23 45 48 52
38 RAMEEZ M 12D 35 94 93 95
42 SANDEEP M 12D 31 63 74 59
44 SWAPNA F 12C 33 69 57 75
b) i) Display the details of female students of '12D'
ii) Display MARKS table sorted on MATH
iii) Display NAME, PHYS+CHEM+MATH when PHYS+CHEM+MATH>255
iv) Display NAME, (PHYS+CHEM+MATH)/3 as PCM of every student of '12C'
c) i) SELECT AVG(MATH), AVG(PHYS) FROM STUDENT S, MARKS M
WHERE S.SNO=M.SNO AND CLA='12C';
ii) SELECT CLA, COUNT(*) FROM STUDENT GROUP BY CLA;
ii) SELECT NAME, PHYS+CHEM+MATH FROM STUDENT S, MARKS M
WHERE S.SNO=M.SNO AND NAME LIKE 'P%';
iv) SELECT MAX(PHYS), MAX(CHEM), MAX(MATH) FROM MARKS;

Page 4 of 4

You might also like