Prev Yr SQL Qs
Prev Yr SQL Qs
Table : DEALER
DCODE DNAME
21 Premium Stationers
23 Soft Plastics
22 Tetra Supply
Page 1 of 11
2. ( a) What do you understand by the terms Cardinality and Degree of a relation in relational database.
(b ) Consider the following tables and answer the questions that follow :
TABLE : GRADUATE
S. No. NAME STIPEND SUBJECT AVERAGE DIV
1 Auro 500 Computer Sc. 78 1
2. Bharti 200 Economics 57 2
3 Dhriti 450 Maths 94 1
4 Kuhikaa 350 Chemistry 95 1
5 Gitagya 400 Physics 60 1
6 Tripti 250 Computer Sc 50 2
TABLE : GUIDE
Subject ADVISOR
Physics Sandip
Computer Science Rizwan
Chemistry Geetika
Maths Rohini
(v)60
(vi) ComputerSc
Maths
Economics
Chemistry
Physics
(vii) Rizwan
(viii)
(b) Consider the following tables EMPLOYEE and INCHARGE and answer (b1) and
(b2) parts of the question:
Table: EMPLOYEE
EMPNAME BASIC DEPARTMENT DATEOFAPP AGE SEX
KARAN 8000 PERSONNEL 27/03/97 35 M
DIVAKAR 9500 COMPUTER 20/01/98 34 M
DIVYA 7300 ACCOUNTS 19/02/97 34 F
ARUN 8350 PERSONNEL 01/01/95 33 M
SABINA 9500 ACCOUNTS 12/01/96 36 F
JOHN 7400 ACCOUNTS 24/02/97 36 M
ROBERT 8250 PERSONNEL 20/02/97 39 M
RUBINA 9450 MAINTENANCE 22/02/98 37 F
VIKAS 7500 COMPUTER 13/01/94 41 M
MOHAN 9300 MAINTENANCE 19/02/98 37 M
Table :INCHARGE
DEPT HEAD
PERSONNEL RAHUL
COMPUTER SATYAM
ACCOUNTS NATH
FINANCE GANESH
MAINTENANCE JACOB
4. .( a) What is the difference between primary key and candidate key of a relation in relational database?
Explain with suitable example. 2
Ans:
Primary key: It is the field or combination of fields through which we can identify a record uniquely. There will
be only one primary key possible in a relation.
Candidate key: The groups of various key or combination of keys which can form primary key is called
candidate keys. There are more than one candidate keys possible in a relation.
13107 Arundeep 5 A 7
16112 Abhinash 1 C 1
11110 Pradipta 12 E 25
10109 Ankita 11 D 2
Admno may be the primary key. (i) admno and (ii) class+sec+roll may be the candidate key.
Page 4 of 11
(b) What is the difference between Cartesian product and natural join of two relations? 2
Ans:
Cartesian product is called unrestricted join. It displays all possible combination of records of both tables. If we
consider following tables( PRODUCT and CLIENT) and to display all combination of records the it will display
25 records.
SELECT * FROM PRODUCT, CLIENT;
Natural Join will join the tables vertically to display all fields for the corresponding records with mathing field
value in both tables. It also avoids to display the common field more than once.
SELECT CLIENT.*, PRODUCTNAME,MANUFACTURER,PRICE FROM PRODUCT, CLIENT WHERE
PRODUCT.P_ID=CLIENT.P_ID;
Consider the following tables PRODUCT and CLIENT and answer( c) and (d) parts of this question.
Table: PRODUCT
P_id Productname Manufacture Price
Table: CLIENT
(ii) To display the details of products whose price is in the range of 50 to 100 ( both values included)
Ans: SELECT * FROM PRODUCT WHERE PRICE BETWEEN 50 AND 100;
Page 5 of 11
(iii) To display the clientname, city from table CLIENT and productname, price from table PRODUCT
with their corresponding matching p_id
Ans: SELECT CLIENTNAME, CITY, PRODUCTNAME,PRICE FROM CLIENT, PRODUCT WHERE
CLIENT.P_ID=PRODUCT.P_ID;
DELHI
MUMBAI
BANGALORE
(ii) Select manufacture, max(price), min(price), count(*) from product group by manufacturer;
Ans:
Manufacturemax(price)min(price)count(*)
LAK 40 40 1
ABC 55 45 2
XYZ 120 95 2
(iii) Select clientname, manufacture from product, client where client.p_id=product.p_id and
client.c_id>=15;
Ans: clientnamemanufacture
FW12 XYZ
TP01 LAK
Shampoo 480
Page 6 of 11
5. (a) Observe the following Table and answer the parts (i) and (ii) accordingly 2
Table: MEMBER
(ii) What are the degree and the cardinality of the above table?
Consider the following tables SUBJECT and TEACHER and answer (b), (c), (d) and (e) parts of this
question: Table: SUBJECT
(i) To display the names of all the subjects for which practical marks are 0.
(iii) To display the names of all the teachers in the ascending order of the Sub_Code.
(iv) To display each subject’s details along with Total_Marks in each subject from the table SUBJECT.
(Total_Marks = Marks_Theory + Marks_Practical).
(ii)
Supatra 041
Shabnam 083
Rashika 042
Vidushi 041
Yash 043
(e) Identify primary keys of the tables SUBJECT and TEACHER. 1
_________________________________________________________________________________________
6. .(a) Explain the concept of Cartesian product of two tables, with the help of appropriate example.2
Ans:
It is called unrestricted join. It gives all possible combinations of records of both tables.
If table 1 contains 3 records and table 2 contains 2 records then Cartesian product will be
6 records.
Table 1 Table 2
Admno Name classsec Admno Eng Maths Sc
111 Abhinash 3E 222 98 99 88
222 Arundeep 7B 111 90 100 99
Page 8 of 11
(b) Consider the following tables PRODUCTS and SUPPLIERS and answer (b1) and (b2) parts of the
question: Table: PRODUCTS
______________________________________________________________________________________
7. What do you understand by Candidate Keys in a table? Give a suitable example of Candidate Keys from a
table containing some meaningful data. 2
Ans:
A table may have more than one such attribute/group of attribute that identifies a row/tuple uniquely. All such
attributes are known as Candidate keys. Out of the candidate keys, one will be the primary key.
(b ) Consider the following tables SUBJECTS and TEACHER and answer the questions (i) to (v) and give
output for (vi) to (vii) : 1X5+ ½X2
Table: SUBJECT
Code Title Marks _Theory Marks_Prac
301 English 100 0
041 Maths 100 0
083 Computer Sc. 70 30
042 Physics 70 30
043 Chemistry 70 30
Table: TEACHER
TCode Name Sub_Code
1 P. Jain 301
2 R. Nagpal 301
3 Supatra 041
4 Shabnam 083
5 Rashika 042
6 Vidushi 041
7 Yash 043
(i) To display each teacher’s name along with his/her respective subject name.
Page 10 of 11
(ii) To display the names of all the subjects for which practical marks are 0.
(iii) To display the total number of teachers in each subject separately.
(iv) To display the names of all the teachers in the ascending order of the Sub_Code.
(v) To display each subject’s details along with Total_Marks in each subject from the table SUBJECT.
(Total_Marks = Marks_Theory + Marks_Practical).
Ans:
(i) select name, title from teacher, subject where teacher.sub_code=subject.ode;
(ii) select title from subject where marks_prac=0;
(iii) select sub_code, count(*) from teacher group by sub_code;
(iv) select name from teacher order by sub_code;
(v) select *, marks_theory+marks_pracTotal_mark from subject;
OUTPUT
(vi) 100
70
(vii)
3 Supatra
4 Shabnam
5 Rashika
6 Vidushi
7 Yash
Page 11 of 11