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

Databases & SQL Ques & Ans

The document contains a series of questions and tasks related to Relational Database Management Systems (RDBMS) and SQL, including examples of tables, queries for extracting data, and operations to illustrate concepts like primary keys, candidate keys, degree, and cardinality. It also includes SQL commands for various queries based on provided data sets for teachers, students, coaches, furniture, games, and workers. The document is structured as a series of exercises aimed at testing knowledge of RDBMS and SQL query writing.

Uploaded by

Rehan Thakur
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Databases & SQL Ques & Ans

The document contains a series of questions and tasks related to Relational Database Management Systems (RDBMS) and SQL, including examples of tables, queries for extracting data, and operations to illustrate concepts like primary keys, candidate keys, degree, and cardinality. It also includes SQL commands for various queries based on provided data sets for teachers, students, coaches, furniture, games, and workers. The document is structured as a series of exercises aimed at testing knowledge of RDBMS and SQL query writing.

Uploaded by

Rehan Thakur
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 24

1.

RDBMS – Descriptive Questions


(i) Give a suitable example of a table with sample data and illustrate Primary and
Candidate keys in it. (CBSE
2012)
(ii) What is the difference between degree and cardinality of a table? What is the
degree and cardinality of the following table: (CBSE
2013)
EN Name Salar
o y
101 John Fedrick 45000
103 Raya 50600
Mazumdar
(iii) Give a suitable example of a table with sample data and illustrate Primary and
Alternate keys in it.
(iv) 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-Delhi 2015)
Id Product Qty Price Transaction
Date
10 Plastic Folder 12" 100 3400 2014-12-14
1
10 Pen Stand 200 4500 2015-01-31
4 Standard
10 Stapler Medium 250 1200 2015-02-28
5
10 Punching Machine 200 1400 2015-03-12
9 Big
10 Stapler Mini 100 1500 2015-02-02
3

(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)

Code Item Qty Price Transaction


Date
1001 Plastic Folder 14” 100 3400 2014‐12‐14
1004 Pen Stand Standard 200 4500 2015‐01‐31
1005 Stapler Mini 250 1200 2015‐02‐28
1009 Punching Machine 200 1400 2015‐03‐12
Small
1003 Stapler Big 100 1500 2015‐02‐02

(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)
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

2. SQL – Writing queries and finding outputs


(i) Write SQL commands for the following queries based on the relation
Teacher given below:
No Name Age Departmen Date_of_join Salar Sex
t y
1 Jugal 34 Computer 10/01/97 1200 M
0
2 Sharmila 31 History 24/03/98 2000 F
0
3 Sandeep 32 Maths 12/12/96 3000 M
0
4 Sangeet 35 History 01/07/99 4000 F
a 0
5 Rakesh 42 Maths 05/09/97 2500 M
0
6 Shyam 50 History 27/06/98 3000 M
0
7 Shiv Om 44 Computer 25/02/97 2100 M
0
8 Shalakh 33 Maths 31/07/97 2000 F
a 0
a) To show all information about the teacher of History department.
b) To list the names of female teachers who are in Maths department.
c) To list the names of all teachers with their date of joining in ascending
order.
d) To display teacher’s name, salary, age for male teachers only.
e) To count the number of teachers with Age>23.
(ii) Given the following relation: STUDENT
No. NameAge Departmen Dateofad Fee Sex
t m
1 Pankaj 24 Computer 10/01/97 120 M
2 Shalini 21 History 24/03/98 200 F
3 Sanjay 22 Hindi 12/12/96 300 M
4 Sudha 25 History 01/07/99 400 F
5 Rakesh 22 Hindi 05/09/97 250 M
6 Shakee 30 History 27/06/98 300 M
l
7 Surya 34 Computer 25/02/97 210 M
8 Shikha 23 Hindi 31/07/97 200 F
Write SQL commands for the following queries
a) To show all information about the students of History department.
b) To list the names of female students who are in Hindi department.
c) To list the names of all students with their date of admission in ascending
order.
d) To display student’s name, fee, age for male students only.
e) To count the number of students with Age>23.

(iii) Write SQL commands for the following queries on the basis of Club relation
given below:
Coach- CoachNam Ag Sports date_of_ap Pay Sex
ID e e p
1 Kukreja 35 Karate 27/03/1996 1000 M
2 Ravina 34 Karate 20/01/1998 1200 F
3 Karan 34 Squash 19/02/1998 2000 M
4 Tarun 33 Basketbal 01/01/1998 1500 M
l
5 Zubin 36 Swimmin 12/01/1998 750 M
g
6 Ketaki 36 Swimmin 24/02/1998 800 F
g
7 Ankita 39 Squash 20/02/1998 2200 F
8 Zareen 37 Karate 22/02/1998 1100 F
9 Kush 41 Swimmin 13/01/1998 900 M
g
10 Shailya 37 Basketbal 19/02/1998 1700 M
l
a) To show all information about the swimming coaches in the club.
b) To list the names of all coaches with their date of appointment
(date_of_app) in descending order.
c) To display a report showing coach name, pay, age, and bonus (15% of
pay) for all coaches.
d) To insert a new row in the Club table with ANY relevant data:
e) Give the output of the following SQL statements:
i. Select COUNT(Distinct Sports) from Club;
ii. Select Min(Age) from Club where SEX = “F”;

(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 DATEOFSTO PRICE DISCOUNT
CK
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 DATEOFSTO PRICE DISCOUN
CK T
1 Wood Double 23/03/03 25000 25
Comfort Bed
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
g) Give the output of following SQL stateme
Note: Outputs of the above mentioned queries should be based on
original data given in both the tables i.e., without considering the
insertion done in (f) part of this question.
(i) Select COUNT(distinct TYPE) from FURNITURE;
(ii) Select MAX(DISCOUNT) from FURNITURE,ARRIVALS;
(iii) Select AVG(DISCOUNT) from FURNITURE where TYPE="Baby cot";
(iv) Select SUM(Price) from FURNITURE where
DATEOFSTOCK<{12/02/02};

(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 Numbe PrizeMone ScheduleDat
r y e
101 Carom 2 5000 23-Jan-2004
Board
102 Badminton 2 12000 12-Dec-2003
103 Table 4 8000 14-Feb-2004
Tennis
105 Chess 2 9000 01-Jan-2004
108 Lawn Tennis 4 25000 19-Mar-2004
PLAYER
PCode Name Gcode
1 Nabi 101
Ahmad
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
ECOD NAM DESIG PLEVEL DOJ DO
E E B
11 Radhey Superviso P001 13-Sep-2004 23-Aug-1981
Shyam r
12 Chander Nath Operator P003 22-Feb-2010 12-Jul-1987
13 Fizza Operator P003 14-June- 14-Oct-1983
2009
15 Ameen Ahmed Mechanic P002 21-Aug-2006 13-Mar-1984
18 Sanya Clerk P002 19-Dec-2005 09-June-
1983
PAYLEVEL
PAYLEVE PAY ALLOWAN
L CE
P001 2600 12000
0
P002 2200 10000
0
P003 1200 6000
0
(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.
(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
Vcod VehicleNa Make Color Capaci Charg
e me ty es
100 Innova Toyota WHITE 7 15
102 SX4 Suzuki BLUE 4 14
104 C Class Mercede RED 4 35
s
105 A-Star Suzuki WHITE 3 14
108 Indigo Tata SILVE 3 12
R
CUSTOMER
CCod CName VCod
e e
1 Hemant 101
Sahu
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
COD INAM QTY PRIC COMPAN TCOD
E E E Y E
1001 DIGITAL PAD 12i 120 1100 XENITA T01
0
1006 LED SCREEN 40 70 3800 SANTORA T02
0
1004 CAR GPS SYSTEM 50 2150 GEOKNOW T01
0
1003 DIGITAL CAMERA 160 8000 DIGICLICK T02
12X
1005 PEN DRIVE 32GB 600 1200 STOREHO T03
ME

TRADERS
TCod TName CITY
e
T01 ELECTRONIC MUMBAI
SALES
T03 BUSY STORE DELHI
CORP
T02 DISP HOUSE INC CHENNA
I
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.
g 1 ) SELECT MAX(PRICE), MIN(PRICE) FROM ITEMS;
g 2 ) SELECT PRICE*QTY AMOUNT FROM ITEMS WHERE
CODE-1004; g 3 ) SELECT DISTINCT TCODE FROM ITEMS;
g 4 ) 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 SNam AREA
e
S01 ABC GK II
Computronics
S02 All Infotech Media CP
S03 Tech Shoppe Nehru Place
S05 Hitech Tech Store SP
ITEM
INo IName Pric SNo
e
T01 Mother Board 1200 S01
0
T02 Hard Disk 5000 S01
T03 Keyboard 500 S02
T04 Mouse 300 S01
T05 Mother Board 1300 S02
0
T06 Key Board 400 S03
T07 LCD 6000 S04
T08 LCD 5500 S05
T09 Mouse 350 S05
T10 Hard disk 4500 S03

(a) Write the SQL queries (1 to 4):


1) To display IName and Price of all the items in the ascending order of their
Price.
2) To display the SNo and SName o all stores located in CP.
3) To display the minimum and maximum price of each IName from the
table Item.
4) To display the IName, price of all items and their respective SName
where they are available.
(b) Write the output of the following SQL commands (1 to 4):
1) SELECT DISTINCT INAME FROM ITEM WHERE PRICE >= 5000;
2) SELECT AREA, COUNT(*) FROM STORE GROUP BY AREA;
3) SELECT COUNT(DISTINCT AREA) FROM STORE;
4) SELECT INAME, PRICE*0.05 DISCOUNT FROM ITEM WHERE SNO IN (‘S02’,
‘S03’);
(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
DCOD DEPARTMENT CITY
E
D01 MEDIA DELHI
D02 MARKETING DELHI
D03 INFRASTRUCTURE MUMBAI
D05 FINANCE KOLKATA
D04 HUMAN RESOURCE MUMBAI

Table: WORKER
WN NAME DOJ DOB GENDE DCOD
O R E
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
DCOD DEPARTMENT LOCATIO
E N
D01 INFRASTRUCTUR DELHI
E
D02 MARKETING DELHI
D03 MEDIA MUMBAI
D05 FINANCE KOLKATA
D04 HUMAN MUMBAI
RESOURCE

Table: EMPLOYEE
ENO NAME DOJ DOB GENDE DCOD
R E
1001 George K 2013090 1991090 MALE D01
2 1
1002 Ryma Sen 2012121 1990121 FEMALE D03
1 5
1003 Mohitesh 2013020 1987090 MALE D05
3 4
1007 Anil Jha 2014011 1984101 MALE D04
7 9
1004 Manila 2012120 1986111 FEMALE D01
Sahai 9 4
1005 R SAHAY 2013111 1987033 MALE D02
8 1
1006 Jaya Priya 2014060 1985062 FEMALE D05
9 3

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.
(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’;
(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’;
2. RDBMS – Descriptive Questions
(i) 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.
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. Any one of these can be
designated as the Primary key.

(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.

(iv) Candidate keys : Id, Product; Primary key : Id


(v) Candidate keys : Code, Item; Primary keys: Code
(vi) Cartesian
Product Degree
= 4 Cardinality
=6

(vii) Cartesian
Product Degree
= 4 Cardinality
=6

3. SQL – Writing queries and finding outputs


(i)
a) SELECT * FROM TEACHER WHERE DEPARTMENT = “History”;
b) SELECT NAME FROM TEACHER WHERE DEPARTMENT = “Maths” AND SEX
= “F”;
c) SELECT NAME FROM TEACHER ORDER BY DATE_OF_JOIN;
d) SELECT NAME, SALARY, AGE FROM TEACHER WHERE SEX = “M”;
e) SELECT COUNT(*) FROM TEACHER WHERE AGE>23;
(ii)
a) SELECT * FROM STUDENT WHERE DEPARTMENT = “History”;
b) SELECT * FROM STUDENT WHERE DEPARTMENT = “Hindi” AND SEX=’F’;
c) SELECT * FROM STUDENT ORDER BY DATEOFADM;
d) SELECT NAME, FEE, AGE FROM STUDENT WHERE SEX=“M”;
e) SELECT COUNT(*) FROM STUDENT AGE>23;
(iii)
a) SELECT * FROM CLUB WHERE SPORTS = “Swimming”;
b) SELECT Name FROM CLUB ORDER BY date_of_app desc;
c) SELECT COACHNAME, PAY, AGE, PAY*15/100 AS BONUS FROM CLUB;
d) INSERT INTO CLUB VALUES (11, “Neelam”, 35, “Basketyball”,
“2000/04/01”, 2200, “F”);
e)
i. 4
ii. 34
(iv)
a) SELECT * FROM FURNITURE WHERE TYPE = “Baby cot”;
b) SELECT ITEMNAME FROM FURNITURE WHERE PRICE > 15000;
c) SELECT ITEMNAME, TYPE FROM FURNITURE WHERE
DATEOFSTOCK<”2002/01/22” ORDER BY ITEMNAME DESC;
d) SELECT ITEMNAME, DATEOFSTOCK FROM FURNITURE WHERE DISCOUNT>25;
e) SELECT COUNT(*) FROM FURNITURE WHERE TYPE=”Sofa”;
f) INSERT INTO ARRIVAL VALUES (14, “Valvet touch”, "Double bed",
“2003/03/03”);
g)
(i) 5
(ii) 30
(iii) 18.33
(iv) 65500

(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
(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)
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;

(ii) SELECT Name FROM Worker


WHERE Gender=’FEMALE’;

(iii) SELECT Wno, Name FROM Worker


WHERE DOB BETWEEN ‘19870101’ AND ‘19911201’;
OR
SELECT Wno, Name FROM Worker
WHERE DOB >=‘19870101’ AND DOB <=‘19911201’

(iv) SELECT COUNT(*) FROM Worker


WHERE GENDER=’MALE’ AND DOJ > ‘19860101’;

(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’;
OR
SELECT Eno,Name FROM Employee
WHERE DOB >=‘19870101’ AND DOB <=‘19911201’;
OR
SELECT Eno,Name FROM Employee
WHERE DOB >‘19870101’ AND DOB <‘19911201’;

(iv) SELECT count(*) FROM Employee


WHERE GENDER=’FEMALE’ AND DOJ > ‘19860101’;
OR
SELECT * FROM Employee
WHERE GENDER=’FEMALE’ AND DOJ > ‘19860101’;

(v) COUNT DCODE


2 D01
2 D05

(vi) Department
INFRASTRUCTURE
MARKETING
MEDIA
FINANCE
HUMAN RESOURCE

(vii) NAME DEPARTMENT


George K INFRASTRUCTURE
Ryma Sen MEDIA

(viii) MAX(DOJ) MIN(DOB)


20140609 19841019

(xii)
(i) SELECT NO, NAME, TDATE FROM TRAVEL ORDER BY NO DESC;

(ii) SELECT NAME FROM TRAVEL


WHERE CODE=101 OR CODE=102;

(iii) SELECT NO, NAME from TRAVEL


WHERE TDATE BETWEEN ‘2015-04-01’ AND ‘2015-12-31’;

(iv) SELECT * FROM TRAVEL WHERE KM > 100 ORDER BY NOP;

(v) COUNT(*) CODE


2 101
2 102

(vi) DISTINCT CODE


101
102
103
104
105

(vii) CODE NAME VTYPE


104 Ahmed Khan CAR
105 Raveena SUV
(viii) NAME KM*PERKM
Raveena 3200
(xiii)
(i) SELECT CNO, CNAME, TRAVELDATE FROM TRAVEL ORDER BY CNO DESC;

(ii) SELECT CNAME FROM TRAVEL


WHERE VODE=V01 OR VCODE=V02;

(iii) SELECT CNO, CNAME from TRAVEL


WHERE TRAVELDATE BETWEEN ‘2015-12-31’ AND ‘2015-05-01’;

(iv) SELECT * FROM TRAVEL


WHERE KM > 120 ORDER BY NOP;
(v)
COUNT(*) VCODE
2 V01
2 V02

(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

You might also like