questions on Databases and SQL
questions on Databases and SQL
(v) Observe the following table carefully and write the names of the most appropriate
columns, which can be considered as (i) candidate keys and (ii) primary key.
(CBSE-Outside Delhi 2015)
(vi) Observe the following STUDENTS and EVENTS tables carefully and write the name of the
RDBMS operation which will be used to produce the output as shown in LIST. Also, find the
Degree and Cardinality of the LIST. (CBSE- Delhi 2016)
STUDENTS EVENTS
No Name EVENTCODE EVENTNAME
1 Tara mani 1001 Programming
2 Jaya Sarkar 1002 IT Quiz
3 Tarini Trikha
LIST
NO NAME EVENTCODE EVENTNAME
1 Tara mani 1001 Programming
1 Tara mani 1002 IT Quiz
2 Jaya Sarkar 1001 Programming
2 Jaya Sarkar 1002 IT Quiz
3 Tarini Trikha 1001 Programming
3 Tarini Trikha 1002 IT Quiz
(vii) Observe the following PARTICIPANTS and EVENTS tables carefully and write the name of
the RDBMS operation which will be used to produce the output as shown in RESULT. Also,
find the Degree and Cardinality of the RESULT. (CBSE- Outside Delhi 2016)
1
QB/XII/083 (new)/Databases and SQL/2020/YK
PARTICIPANTS EVENTS
PNo Name EVENTCODE EVENTNAME
1 Aruanabha Tariban 1001 IT Quiz
2 John Fedricks 1002 Group Debate
3 Kanti Desai
RESULT
PNO NAME EVENTCODE EVENTNAME
1 Aruanabha Tariban 1001 IT Quiz
1 Aruanabha Tariban 1002 Group Debate
2 John Fedricks 1001 IT Quiz
2 John Fedricks 1002 Group Debate
3 Kanti Desai 1001 IT Quiz
3 Kanti Desai 1002 Group Debate
(iii) Write SQL commands for the following queries on the basis of Club relation given below:
2
QB/XII/083 (new)/Databases and SQL/2020/YK
(iv) Write SQL commands for (a) to (f) and write the outputs for (g) on the basis of tables
FURNITURE and ARRIVALS
FURNITURE
NO ITEMNAME TYPE DATEOFSTOCK PRICE DISCOUNT
1 White lotus Double Bed 23/02/02 30000 25
2 Pink feather Baby cot 20/01/02 7000 20
3 Dolphin Baby cot 19/02/02 9500 20
4 Decent Office Table 01/01/02 25000 30
5 Comfort zone Double Bed 12/01/02 25000 25
6 Donald Baby cot 24/02/02 6500 15
7 Royal Finish Office Table 20/02/02 18000 30
8 Royal tiger Sofa 22/02/02 31000 30
9 Econo sitting Sofa 13/12/01 9500 25
10 Eating Paradise Dining Table 19/02/02 11500 25
ARRIVALS
NO ITEMNAME TYPE DATEOFSTOCK PRICE DISCOUNT
1 Wood Comfort Double Bed 23/03/03 25000 25
2 Old Fox Sofa 20/02/03 17000 20
3 Micky Baby cot 21/02/03 7500 15
a) To show all information about the Baby cots from the FURNITURE table.
b) To list the ITEMNAME which are priced at more than 15000 from the FURNITURE table.
c) To list ITEMNAME and TYPE of those items, in which date of stock is before 22/01/02
from the FURNITURE table in descending of ITEMNAME.
d) To display ITEMNAME and DATEOFSTOCK of those items, in which the discount
percentage is more than 25 from FURNITURE table.
e) To count the number of items, whose TYPE is "Sofa" from FURNITURE table.
f) To insert a new row in the ARRIVALS table with the following data:
14,“Valvet touch”, "Double bed", {25/03/03}, 25000,30
3
QB/XII/083 (new)/Databases and SQL/2020/YK
(v) Consider the following tables GAMES and PLAYER. Write SQL commands for the statements
(a) to (d) and give outputs for SQL queries (E1) to (E4)
GAMES
GCode GameName Number PrizeMoney ScheduleDate
101 Carom Board 2 5000 23-Jan-2004
102 Badminton 2 12000 12-Dec-2003
103 Table Tennis 4 8000 14-Feb-2004
105 Chess 2 9000 01-Jan-2004
108 Lawn Tennis 4 25000 19-Mar-2004
PLAYER
PCode Name Gcode
1 Nabi Ahmad 101
2 Ravi Sahai 108
3 Jatin 101
4 Nazneen 103
(a) To display the name of all Games with their Gcodes
(b) To display details of those games which are having PrizeMoney more than 7000.
(c) To display the content of the GAMES table in ascending order of ScheduleDate.
(d) To display sum of PrizeMoney for each of the Number of participation groupings (as
shown in column Number)
(e1) SELECT COUNT(DISTINCT Number) FROM GAMES;
(e2) SELECT MAX(ScheduleDate),MIN(ScheduleDate) FROM GAMES;
(e3) SELECT SUM(PrizeMoney) FROM GAMES;
(e4) SELECT DISTINCT Gcode FROM PLAYER;
(vi) Consider the following tables WORKER and PAYLEVEL and answer (a) and (b) parts of this
question: (CBSE 2011)
WORKER
ECODE NAME DESIG PLEVEL DOJ DOB
11 Radhey Shyam Supervisor P001 13-Sep-2004 23-Aug-1981
12 Chander Nath Operator P003 22-Feb-2010 12-Jul-1987
13 Fizza Operator P003 14-June-2009 14-Oct-1983
15 Ameen Ahmed Mechanic P002 21-Aug-2006 13-Mar-1984
18 Sanya Clerk P002 19-Dec-2005 09-June-1983
PAYLEVEL
PAYLEVEL PAY ALLOWANCE
P001 26000 12000
P002 22000 10000
P003 12000 6000
(a) Write SQL commands for the following statements:
(i) To display the details of all WORKERs in descending order of DOB.
(ii) To display NAME and DESIG of those WORKERs whose PLEVEL is either P001 or
P002.
4
QB/XII/083 (new)/Databases and SQL/2020/YK
(iii) To display the content of all the WORKERs table, whose DOB is in between ’19-
JAN-1984’ and ’18-JAN-1987’.
(iv) To add a new row with the following:
19, ‘Daya kishore’, ‘Operator’, ‘P003’, ’19-Jun-2008’, ’11-Jul-1984’
(b) Give the output of the following SQL queries:
(i) SELECT COUNT(PLEVEL), PLEVEL FROM WORKER GROUP BY PLEVEL;
(ii) SELECT MAX(DOB), MIN(DOJ) FROM WORKER;
(iii) SELECT Name, Pay FROM WORKER W, PAYLEVEL P WHERE W.PLEVEL=P.PLEVEL
AND W.ECODE<13;
(iv) SELECT PLEVEL, PAY+ALLOWANCE FROM PAYLEVEL WHERE PLEVEL=’P003’;
(vii) Consider the following tables CABHUB and CUSTOMER and answer (a) and (b) parts of this
question: (CBSE 2012)
CABHUB
Vcode VehicleName Make Color Capacity Charges
100 Innova Toyota WHITE 7 15
102 SX4 Suzuki BLUE 4 14
104 C Class Mercedes RED 4 35
105 A-Star Suzuki WHITE 3 14
108 Indigo Tata SILVER 3 12
CUSTOMER
CCode CName VCode
1 Hemant Sahu 101
2 Raj Lal 108
3 Feroza Shah 105
4 Ketan Dhal 104
(a) Write SQL commands for the following statements:
1) To display the names of all white colored vehicles
2) To display name of vehicle, make and capacity of vehicles in ascending order of
their sitting capacity
3) To display the highest charges at which a vehicle can be hired from CABHUB.
4) To display the customer name and the corresponding name of the vehicle hired
by them.
(b) Give the output of the following SQL queries:
1) SELECT COUNT(DISTINCT Make) FROM CABHUB;
2) SELECT MAX(Charges), MIN(Charges) FROM CABHUB;
3) SELECT COUNT(*), Make FROM CABHUB;
4) SELECT VehicleName FROM CABHUB WHERE Capacity = 4;
(viii) Write SQL queries for (a) to (f) and write the outputs for the SQL queries mentioned shown
in (g1) to (g4) parts on the basis of tables ITEMS and TRADERS: (CBSE 2013)
ITEMS
CODE INAME QTY PRICE COMPANY TCODE
1001 DIGITAL PAD 12i 120 11000 XENITA T01
1006 LED SCREEN 40 70 38000 SANTORA T02
1004 CAR GPS SYSTEM 50 21500 GEOKNOW T01
1003 DIGITAL CAMERA 12X 160 8000 DIGICLICK T02
1005 PEN DRIVE 32GB 600 1200 STOREHOME T03
TRADERS
TCode TName CITY
T01 ELECTRONIC SALES MUMBAI
T03 BUSY STORE CORP DELHI
T02 DISP HOUSE INC CHENNAI
5
QB/XII/083 (new)/Databases and SQL/2020/YK
a) To display the details of all the items in the ascending order of item names (i.e.
INAME).
b) To display item name and price of all those items, whose price is in range of
10000 and 22000 (both values inclusive).
c) To display the number of items, which are traded by each trader. The expected
output of this query should be:
T01 2
T02 2
T03 1
d) To display the price, item name and quantity (i.e. qty) of those items which
have quantity more than 150.
e) To display the names of those traders, who are either from DELHI or from
MUMBAI.
f) To display the names of the companies and the names of the items in descending
order of company names.
g1 ) SELECT MAX(PRICE), MIN(PRICE) FROM ITEMS;
g2 ) SELECT PRICE*QTY AMOUNT FROM ITEMS WHERE CODE-1004;
g3 ) SELECT DISTINCT TCODE FROM ITEMS;
g4 ) SELECT INAME, TNAME FROM ITEMS I, TRADERS T WHERE I.TCODE=T.TCODE
AND QTY<100;
(ix) Answer the (a) and (b) on the basis of the following tables STORE and ITEM: (CBSE 2014)
STORE
SNo SName AREA
S01 ABC Computronics GK II
S02 All Infotech Media CP
S03 Tech Shoppe Nehru Place
S05 Hitech Tech Store SP
ITEM
INo IName Price SNo
T01 Mother Board 12000 S01
T02 Hard Disk 5000 S01
T03 Keyboard 500 S02
T04 Mouse 300 S01
T05 Mother Board 13000 S02
T06 Key Board 400 S03
T07 LCD 6000 S04
T08 LCD 5500 S05
T09 Mouse 350 S05
T10 Hard disk 4500 S03
6
QB/XII/083 (new)/Databases and SQL/2020/YK
(x) Consider the following DEPT and WORKER tables. Write SQL queries for (i) to (iv) and find
outputs for SQL queries (v) to (viii): (CBSE-Delhi 2015)
Table: DEPT
DCODE DEPARTMENT CITY
D01 MEDIA DELHI
D02 MARKETING DELHI
D03 INFRASTRUCTURE MUMBAI
D05 FINANCE KOLKATA
D04 HUMAN RESOURCE MUMBAI
Table: WORKER
WNO NAME DOJ DOB GENDER DCODE
1001 George K 2013-09-02 1991-09-01 MALE D01
1002 Ryma Sen 2012-12-11 1990-12-15 FEMALE D03
1003 Mohitesh 2013-02-03 1987-09-04 MALE D05
1007 Anil Jha 2014-01-17 1984-10-19 MALE D04
1004 Manila Sahai 2012-12-09 1986-11-14 FEMALE D01
1005 R SAHAY 2013-11-18 1987-03-31 MALE D02
1006 Jaya Priya 2014-06-09 1985-06-23 FEMALE D05
Note: DOJ refers to date of joining and DOB refers to date of Birth of workers.
(i) To display Wno, Name, Gender from the table WORKER in descending order of
Wno.
(ii) To display the Name of all the FEMALE workers from the table WORKER.
(iii) To display the Wno and Name of those workers from the table WORKER who
are born between ‘1987-01-01’ and ‘1991-12-01’.
(iv) To count and display MALE workers who have joined after ‘1986-01-01’.
(v) SELECT COUNT(*), DCODE FROM WORKER GROUP BY DCODE HAVING
COUNT(*)>1;
(vi) SELECT DISTINCT DEPARTMENT FROM DEPT;
(vii) SELECT NAME, DEPARTMENT, CITY FROM WORKER W,DEPT D WHERE
W.DCODE=D.DCODE AND WNO<1003;
(viii) SELECT MAX(DOJ), MIN(DOB) FROM WORKER;
(xi) Consider the following DEPT and EMPLOYEE tables. Write SQL queries for (i) to (iv) and
find outputs for SQL queries (v) to (viii). (CBSE-Outside Delhi 2015)
Table: DEPT
DCODE DEPARTMENT LOCATION
D01 INFRASTRUCTURE DELHI
D02 MARKETING DELHI
D03 MEDIA MUMBAI
D05 FINANCE KOLKATA
D04 HUMAN RESOURCE MUMBAI
Table: EMPLOYEE
ENO NAME DOJ DOB GENDER DCODE
1001 George K 20130902 19910901 MALE D01
1002 Ryma Sen 20121211 19901215 FEMALE D03
1003 Mohitesh 20130203 19870904 MALE D05
1007 Anil Jha 20140117 19841019 MALE D04
1004 Manila Sahai 20121209 19861114 FEMALE D01
1005 R SAHAY 20131118 19870331 MALE D02
1006 Jaya Priya 20140609 19850623 FEMALE D05
Note: DOJ refers to date of joining and DOB refers to date of Birth of employees.
(i) To display Eno, Name, Gender from the table EMPLOYEE in ascending order of Eno.
(ii) To display the Name of all the MALE employees from the table EMPLOYEE.
7
QB/XII/083 (new)/Databases and SQL/2020/YK
(iii) To display the Eno and Name of those employees from the table EMPLOYEE who
are born between '1987‐01‐01' and '1991‐12‐01'.
(iv) To count and display FEMALE employees who have joined after '1986‐01‐01'.
(v) SELECT COUNT(*),DCODE FROM EMPLOYEE
GROUP BY DCODE HAVING COUNT(*)>1;
(vi) SELECT DISTINCT DEPARTMENT FROM DEPT;
(vii) SELECT NAME, DEPARTMENT FROM EMPLOYEE E, DEPT
D WHERE E.DCODE=D.DCODE AND EN0<1003;
(viii) SELECT MAX(DOJ), MIN(DOB) FROM EMPLOYEE;
(xii) Write SQL queries for (i) to (iv) and find outputs for SQL queries (v) to (viii), which are based on
the tables. (CBSE- Delhi 2016)
Table: VEHICLE
Code VTYPE PERKM
101 VOLVO BUS 160
102 AC DELUXE BUS 150
103 ORDINARY BUS 90
105 SUV 40
104 CAR 20
Note:
• PERKM is Freight Charges per kilometer
• VTYPE is Vehicle Type
Table: TRAVEL
NO NAME TDATE KM CODE NOP
101 Janish Kin 2015-11-13 200 101 32
103 Vedika sahai 2016-04-21 100 103 45
105 Tarun Ram 2016-03-23 350 102 42
102 John Fen 2016-02-13 90 102 40
107 Ahmed Khan 2015-01-10 75 104 2
104 Raveena 2015-05-28 80 105 4
106 Kripal Anya 2016-02-06 200 101 25
Note :
• NO is Traveller Number
• KM is Kilometer travelled
• NOP is number of travellers travelled in vehicle
• TDATE is Travel Date
(i) To display NO, NAME, TDATE from the table TRAVEL in descending order of NO.
(ii) To display the NAME of all the travellers from the table TRAVEL who are travelling
by vehicle with code 101 or 102.
(iii) To display the NO and NAME of those travellers from the table TRAVEL who
travelled between ‘2015-12-31’ and ‘2015-04-01’.
(iv) To display all the details from table TRAVEL for the travellers, who have travelled
distance more than 100 KM in ascending order of NOP.
(v) SELECT COUNT (*), CODE FROM TRAVEL GROUP BY CODE HAVING
COUNT(*)>1;
(vi) SELECT DISTINCT CODE FROM TRAVEL;
(vii) SELECT A.CODE,NAME,VTYPE FROM TRAVEL A,VEHICLE B WHERE
A.CODE=B.CODE AND KM<90;
(viii) SELECT NAME,KM*PERKM FROM TRAVEL A, VEHICLE B WHERE
A.CODE=B.CODE AND A.CODE=‘105’;
8
QB/XII/083 (new)/Databases and SQL/2020/YK
(xiii) Write SQL queries for (i) to (iv) and find outputs for SQL queries (v) to (viii), which are based on
the tables. (CBSE- Outside Delhi 2016)
Table: VEHICLE
VCODE VEHICLETYPE PERKM
V01 VOLVO BUS 150
V02 AC DELUXE BUS 125
V03 ORDINARY BUS 80
V05 SUV 30
V04 CAR 18
Note:
• PERKM is Freight Charges per kilometer
Table: TRAVEL
CNO CNAME TRAVELDATE KM VCODE NOP
101 K.Niwal 2015-12-13 200 V01 32
103 Fredrick Sym 2016-03-21 120 V03 45
105 Hitesh Jain 2016-04-23 450 V02 42
102 Ravi anish 2016-01-13 80 V02 40
107 John Malina 2015-02-10 65 V04 2
104 Sahanubhuti 2016-01-28 90 V05 4
106 Ramesh jaya 2016-04-06 100 V01 25
Note :
• KM is Kilometer travelled
• NOP is number of travellers travelled in vehicle
• TDATE is Travel Date
(i) To display CNO, CNAME, TRAVELDATE from the table TRAVEL in descending
order of CNO.
(ii) To display the CNAME of all the customers from the table TRAVEL who are
travelling by vehicle with code V01 or V02.
(iii) To display the CNO and CNAME of those customers from the table TRAVEL who
travelled between ‘2015-12-31’ and ‘2015-05-01’.
(iv) To display all the details from table TRAVEL for the customers, who have travelled
distance more than 120 KM in ascending order of NOP.
(v) SELECT COUNT (*), VCODE FROM TRAVEL GROUP BY V CODE
HAVING COUNT(*)>1;
(vi) SELECT DISTINCT VCODE FROM TRAVEL;
(vii) SELECT A.VCODE,CNAME,VEHICLETYPE FROM TRAVEL A,VEHICLE B
WHERE A.VCODE=B.VCODE AND KM<90;
(viii) SELECT CNAME,KM*PERKM FROM TRAVEL A, VEHICLE B WHERE
A.VCODE=B.VCODE AND A.VCODE=‘V05’;
9
QB/XII/083 (new)/Databases and SQL/2020/YK
(ii) Degree of a table is the number of coulmns (attributes) in It, whereas Cardinality is the
number of rows (tuples) in it.
Degree of the given table is 3 and its Cardinality is 2.
(iii) A table may have more than one such attribute/group of attributes that identify a row/tuple
uniquely. All such attribute(s)/group(s) are known as Candidate keys. Out of the candidate
keys, one is selected as primary key and the other keys are known an alternate keys.
Example:
Relation: Stock
Ino Item Qty Price
I01 Pen 560 2
I02 Pencil 600 1
I03 CD 200 3
In this relation Ino and Item are Candidate keys. If Ino is selected as the primary key, then
Item will be the alternate key, and vice-versa.
10
QB/XII/083 (new)/Databases and SQL/2020/YK
(v)
a) SELECT GAMENAME, GCODE FROM GAMES;
b) SELECT * FROM GAMES WHERE PRZEMONEY > 7000;
c) SELECT * FROM GAMES ORDER BY SCHEDULEDATE;
d) SELECT NUMBER, SUM(PRIZEMONEY) FROM GAMES GROUP BY NUMBER;
(e1) 2
4
(e2) MAX(ScheduleDate) MIN(ScheduleDate)
----------------- -----------------
19-Mar-2004 12-Dec-2003
(e3) 59000
(e4) 101
108
103
(vi)
(a)
(i) SELECT * FROM WORKER ORDER BY DOB DESC;
(ii) SELECT NAME, DESIG FROM WORKER WHERE PLEVEL IN (“P001”,
“P002”);
(iii) SELECT * FROM WORKER WHERE DOB BETWEEN “19-JAN-1984” AND “18-
JAN-1987”;
(iv) INSERT INTO WORKER VALUES
(19, ‘Daya kishore’, ‘Operator’, ‘P003’, ’19-Jun-2008’, ’11-
Jul-1984’);
(b)
(i)
COUNT(PLEVEL) PLEVEL
1 P001
2 P002
2 P003
(ii)
MAX(DOB)) MIN(DOJ)
12-Jul-1987 13-Sep-2004
(iii)
Name Pay
Radhey Shyam 26000
Chander Nath 12000
(iv)
PLEVEL PAY+ALLOWANCE
P003 18000
11
QB/XII/083 (new)/Databases and SQL/2020/YK
(vii)
(a)
1) SELECT VehicleName FROM CARHUB WHERE Color = ‘WHITE’;
2) SELECT VehicleName, Make, Capacity FROM CARHUB ORDER BY
CAPACITY;
3) SELECT MAX(Charges) FROM CARHUB;
4) SELECT CName, VehicleName, FROM CUSTOMER, CARHUB
WHERE CUSTOMER.Vcode = CARHUB.Vcode;
(b)
1)
COUNT(DISTINCT Make)
4
2)
MAX(Charges) MIN(Charges)
35 12
3)
COUNT(*)
5
4)
VehicleName
SX4
C Class
(viii)
a) SELECT * FROM ITEMS ORDER BY INAME;
b) SELECT INAME, PRICE FROM ITEMS WHERE PRICE BETWEEN 10000 AND
22000;
c) SELECT TCODE, COUNT(*) FROM ITEMS GROUP BY TCODE;
d) SELECT PRICE, INAME, QTY FROM ITEMS WHERE QTY > 150;
e) SELECT INAME FROM TRADERS WHERE CITY IN (‘DELHI’, ‘MUMBAI’);
f) SELECT COMPANY, INAME FROM ITEMS ORDER BY COMPANY DESC;
g1)
MAX(PRICE) MIN(PRICE)
38000 1200
g2)
AMOUNT
1075000
g3)
DISTINCT TCODE
T01
T02
T03
g4)
INAME TNAME
LED SCREEN 40 DISP HOUSE INC
CAR GPS SYSTEM ELECTRONIC SALES
(ix)
(a)
1) SELECT IName, price from Item ORDER BY Price;
2) SELECT SNo, SName FROM Store WHERE Area=’CP’;
3) SELECT IName, MIN(Price), MAX(Price) FROM Item GROUP BY
IName;
4) SELECT IName, Price, SName FROM Item, Store Where Item.SNo =
Store.SNo;
(b)
12
QB/XII/083 (new)/Databases and SQL/2020/YK
1)
DISTINCT INAME
Hard disk
LCD
Mother Board
2)
Area Count(*)
CP 2
GK II 1
Nehru Place 2
3)
COUNT(DISTINCT AREA)
3
4)
INAME DISCOUNT
Keyboard 25
Mother Board 650
Hard Disk 225
(x)
(i) SELECT Wno,Name,Gender FROM Worker
ORDER BY Wno DESC;
(v)
COUNT(*) DCODE
2 D01
2 D05
(vi)
Department
MEDIA
MARKETING
INFRASTRUCTURE
FINANCE
HUMAN RESOURCE
(vii)
NAME DEPARTMENT CITY
George K MEDIA DELHI
Ryma Sen INFRASTRUCTURE MUMBAI
(viii)
MAX(DOJ) MIN(DOB)
2014-06-09 1984-10-19
(xi)
(i) SELECT Eno,Name,Gender FROM Employee ORDER BY Eno;
(ii) SELECT Name FROM Employee WHERE Gender=’MALE’;
(iii) SELECT Eno,Name FROM Employee
WHERE DOB BETWEEN ‘19870101’ AND ‘19911201’;
13
QB/XII/083 (new)/Databases and SQL/2020/YK
OR
SELECT Eno,Name FROM Employee
WHERE DOB >=‘19870101’ AND DOB <=‘19911201’;
OR
SELECT Eno,Name FROM Employee
WHERE DOB >‘19870101’ AND DOB <‘19911201’;
(vi) Department
INFRASTRUCTURE
MARKETING
MEDIA
FINANCE
HUMAN RESOURCE
(xii)
(i) SELECT NO, NAME, TDATE FROM TRAVEL ORDER BY NO DESC;
14
QB/XII/083 (new)/Databases and SQL/2020/YK
(xiii)
(i) SELECT CNO, CNAME, TRAVELDATE FROM TRAVEL ORDER BY CNO DESC;
(vi)
DISTINCT VCODE
V01
V02
V03
V04
V05
(vii)
VCODE CNAME VEHICLETYPE
V02 Ravi Anish AC DELUXE BUS
V04 John Malina CAR
(viii)
CNAME KM*PERKM
Sahanubhuti 2700
15