Test Generator
Test Generator
Ans :
A column or a set of columns which can uniquely identify a row in a relation.
Primary key cannot have Null values.
For example AdmNo(Admission No) in table Student.
Ans :
CHAR VARCHAR
• It is fixed length
• It is variable length string.
string.
• They are right- • They are not right‑padded
padded with spaces to with space. The length is
the specified length. actual data it contains.
7 What is the purpose of BETWEEN Clause? 1
Ans :
This clause is used to filter the record(s) by providing the range in a column which
contains only a numeric value Text, Data can also be used with BETWEEN clause.
Ans : (b)
12 A Table customer contains 5 rows and 7 columns. What will be its cardinality and 1
degree?
(a) Degree 7, Cardinality 5.
(b) Degree 5, Cardinality 7.
(c) Degree 5, Cardinality 7.
(d) Cardinality 7, Degree 7.
Ans : (a)
13Observe the following STUDENTS and EVENTS tables carefully and write the name 2
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.
Ans :
Candidate key(s), which is not selected as Primary Key, is known as Alternate
key(s).
16 Observe the following table and answer the parts (i) and (ii) accordingly 3
Table: Product
Pno Name Qty PurchaseDate
101 Pen 102 12-12-2011
102 Pencil 201 21-02-2013
103 Eraser 90 09-08-2010
109 Sharpener 90 31-08-2012
113 Clips 900 12-12-2011
(a) Write the names of most appropriate columns, which can be considered as
candidate keys.
(b) What is the degree and cardinality of the above table?
Ans : Candidate Key: Pno, Name Degree:4 Cardinality:5
Ans :
19Write SQL queries for (a) to (f) and write the outputs for the SQL queries mentioned 5
shown in (g1) to (g4) parts on the basis of tables ITEMS and TRADERS: [Delhi
2013]
Table: ITEMS
CODE INAME QTY PRICE COMPANY TCODE
DIGITAL
1001 120 11000 XENITA T01
PAD 12i
LED
1006 70 38000 SANTORA T02
SCREEN 40
CAR GPS
1004 50 21500 GEOKNOW T01
SYSTEM
DIGITAL
1003 CAMERA 160 8000 DIGICLICK T02
12X
PEN DRIVE
1005 600 1200 STOREHOME T03
32GB
Table: TRADERS
TCode TName CITY
T01 ELECTRONIC SALES MUMBAI
T03 BUSY STORE CORP DELHI
T02 DISP HOUSE INC CHENNAI
(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;
Ans :
20Consider the following DEPT and WORKER tables. Write SQL queries for (i) to (iv) 5
and find outputs for SQL queries (v) to (viii): [Delhi 2015]
Table: DEPT
DCODE DEPARTMENT CITY
D01 MEDIA DELHI
D02 MARKETING DELHI
D03 INFRASTRUCTURE MUMBAI
D05 FINANCE KOLKATA
HUMAN
D04 MUMBAI
RESOURCE
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;
Ans :