Beruflich Dokumente
Kultur Dokumente
Name
Arpit
Zarina
Kareem
Arun
Zubin
Ketika
Ankita
Zareen
Kush
Shilpa
Age
62
22
32
12
30
16
29
45
19
23
Department
Surgery
ENT
Orthopedic
Surgery
ENT
ENT
Cardiology
Gynecology
Cardiology
Nuclear Medicine
Dateofadm
21/10/98
12/12/97
19/02/98
11/01/98
12/01/98
24/02/98
20/02/98
22/02/98
13/01/98
21/02/98
Charges
300
250
200
300
250
250
800
300
800
400
Sex
M
F
M
M
M
F
F
F
M
F
Dateofrt
Salary
d
1 Pankaj
54
Engg.
10/01/97
1200
2 Shalini
41
Estbl
24/03/98
2000
3 Sanjay
32
Engg.
12/12/96
3500
4 Sudha
25
Science
01/07/99
4700
5 Rakesh
32
Engg.
05/09/97
2500
6 Shakeel
40
Language
27/06/98
3000
7 Surya
44
Estbl.
25/02/97
2100
8 Shikha
33
Science
31/07/97
2600
Write SQL commands for (b) to (g) and write output for(h).
(b) To show all information about the employees of Engg. Branch
Ans. SELECT * FROM employee WHERE branch= Engg.;
Sex
M
F
M
F
M
M
M
F
Grade2
A
C
B
A
A
C
Assign a value 200 for marks for all those who are getting grade B or grade A in both
Game1 and game2.
Ans.: UPDATE sports SET marks=200 WHERE grade1= A OR garde2= A or grade1= B OR
garde2= B;
(vii) Arrange the whole table in the alphabetical order of Name.
Ans.: SELECT * FROM sports ORDER BY name;
Explain Cartesian product of two relations:
Ans.: Cartesian product of two relations: The Cartesian Product of two relations is the combination of
tuples / records belonging to the two tables / relations. The Cartesian Product is a binary operation and is
denoted by (X). The degree of new relation is the sum of the degrees of two relations on which Cartesian
Product is performed. The number of tuples of the new relation is equal to the product of the number of
tuples of the two relations on which Cartesian Product is performed.
Que 5YEAR : 2002
(a) Differentiate between Data Definition Language and Data Manipulation Language.
Ans.:
DDL
DML
1. Data Definition Language
1. Data Manipulation Language
2. It provides statements for creation and deletion 2. It provides statements fro manipulation of the
of database.
database.
3. Examples: CREATE TABLE, ALTER TABLE
3. Examples: INSERT, DELETE, UPDATE
(b) Given the following Teacher relation : Write SQL command for question (b) to (g)
No Name
Department
Dteofjoining
Salary
Sex
1 Raja
Computer
21/05/98
8000
M
2 Sangita
History
21/05/97
9000
F
3 Ritu
Sociology
29/08/98
8000
F
4 Kumar
Linguistics
13/06/96
10000
M
5 Venkat
History
31/10/99
8000
M
6 Sidhu
Computer
21/05/86
14000
M
7 Aishwarya
Sociology
11/01/88
12000
F
Databases and SQL
6
Type
Double Bed
Dateofstock
23/02/02
Price
32000
Discount
15
Thunderbolts
T001
T002
My First C++
C++
Brainworks
Fast Cook
C001
Table: Issued
Book_Id
F001
T001
C001
Author_Name
William
Hopkins
Anna Roberts
Brian & Brooke
A.W.Rossaine
Publishers Price
First
750
Publ.
First
700
Publ.
EPB
250
TDH
325
Lata Kapoor
EPB
Type
Fiction
Quantity
10
Fiction
Text
Text
10
5
350 Cookery
Quantity_Issued
3
1
5
Que 8 CBSE 2
(a) What is primary key in a table? What is first normal from a database?
Primary Key: It is set of one or more attributes that can uniquely identify tuples or records within a table
or relation.
First Normal Form: A table / relation is said to be in First Normal Form (1NF) if and only if all
underlying domains of the relation contain atomic (individual) values.
Databases and SQL
11
ParticipantsNum PrizeMoney
1001
1002
1003
1005
1008
16
10
12
12
10
Relay 100X4
High Jump
Shot Put
Long Jump
Discuss Throw
Table: COACH
PCode
Name
10000
12000
8000
9000
15000
Schedul
eDate
23-Jan-2004
12-Dec-2003
14-Feb-2004
01-Jan-2004
19-Mar-2004
ACode
Ahmed Hussain
1001
2
3
Ranvinder
Janila
1008
1001
Naaz
1003
CBSE-II: 2004
(a) What do you understand by Primary Key and Candidate Key? 2
Answer: Primary Key: An attribute or set of attributes, which are used to identify a tuple
(record / row) uniquely is known as Primary Key.
Candidate Key: If a table has more than one such attributes which uniquely identify a tuple and are
eligible to be the primary key, all such attributes are known as Candidate Keys.
(b) Consider the following tables GAMES and PLAYER. Wtite SQL
Commands for the statements (i) to (iv) and give outputs for SQL queries
(v) to (viii)
6
Table: GAMES
Gcode
GameName
Number
PrizeMoney ScheduleDate
101
Carom Board
5000 23-Jan-2004
102
Badminton
12000 12-Dec-2003
103
Table Tennis
8000 14-Feb-2004
105
Chess
9000 01-Jan-2004
108
Lawn Tennis
25000 19-Mar-2004
Table: PLAYER
PCode Name
GCode
1
2
3
4
5 (a) What do you understand by the terms Candidate Key and Cardinality of a relation in a
relational database?
2
Ans.: (a) Candidate Key: The attribute (Column) or set of attributes (Columns)
which can identify a tuple/row uniquely are known as Candidate Key(s).
Databases and SQL
14
SALARY
BENEFITS
102
75000
105
85000
25000 Director
70000
15000 Manager
210
75000
12500 Manager
255
50000
12000 Clerk
300
45000
10000 Clerk
335
40000
10000 Clerk
400
32000
144
'
DESIGNATION
15000 Manager
7500 Salesman
28000
451
7500 Salesman
WORKERS
W_ID
FIRSTNAME
LASTNAME
ADDRESS
CITY
102
Sam
'Tones
33 Elm St.
Paris
105
Sarah
Ackerman
New York
144
Manila
Sengupta
24 Friends Street
New Delhi
210
George
Smith
83 First Street
Howard
255
300
335
403
451
Mary
Robert
Henry
Ronny
Pat
Jones
Samuel
Williams
Lee
Thompson
Losantiville
Washington
Boston
New York
Paris
(i) To display W_ID, Firstname, Address and City of all' employees living in
New York from the table .WORKERS.
(b) (i) SELECT W_ID,FIRSTNAME,ADDRESS,CITY FROM
WORKERS WHERE CITY='New York';
Databases and SQL
15
FIRSTNAME
George
Mary
Sam
Sarah
Manila
Robert
Henry
Rachel
Peter
LASTNAME
Smith
Jones
Tones
Ackerman
Sengupta
Samuel
Williams
Lee
Thompson
ADDRESS
83 First Street
842 Vine Ave.
33 Elm St.
440 U.S 110
24 Friends Street
9 Fifth Cross
12 Moore Street
121 Harrison St.
11 Red Road
CITY
Howard
Losantiville
Paris
Upton
New Delhi
Washington
Boston
New York
Paris
EMPSALARY
EMPID SALARY BENEFITS DESIGNATION
010
75000 15000
Manager
105
65000 15000
Manager
152
80000 25000
Director
215
75000 12500
Manager
244
50000 12000
Clerk
300
45000 10000
Clerk
335
40000 10000
Clerk
400
32000 7500
Salesman
441
28000 7500
Salesman
(i) To display Firstname, Lastname, Address and City of all employees
living in
Paris from the table EMPLOYEES.
(b) (i)
Select FIRSTNAME, LASTNAME, ADDRESS, CITY From
EMPLOYEES
Where CITY= Paris;
[
Marks for each part (here parts are separated into lines for
convenience) of correct SQL Command]
(ii) To display the content of EMPLOYEES table in descending order of
FIRSTNAME.
(ii)
Select * From EMPLOYEES
Order By FIRSTNAME;
[ Marks for each part (here parts are separated into lines for
convenience) of correct SQL Command]
Databases and SQL
18
(v)
FIRSTNAME, SALARY
SELECT
FROM EMPLOYEES, EMPSALARY
WHERE DESIGNATION = Salesman AND
EMPLOYEES.EMPID=EMPSALARY.EMPID;
v)
FIRSTNAME
SALARY
Rachel
32000
Peter
28000
[ Mark for correct result]
Note: Heading is Optional
(vi)
SELECT COUNT(DISTINCT DESIGNATION)FROM EMPSALARY;
(vi)
Databases and SQL
19
(viii)
SELECT SUM(BENEFITS)
FROM EMPLOYEES
WHERE DESIGNATION = Clerk;
(viii)
( Mark for mentioning the error)
OR
( Mark for attempting this part of the question)
OR
( Mark for correctly attempting any two part of the
SQL question)
YEAR 2006 ( OUTSIDE DELHI)
5.(a) What are DDL and DML?
[2]
(a) DDL Data Definition Language
DML Data Manipulation Language
(1 Mark each for correct full form OR correctly explaining with the
help of examples)
(b) Study the following tables FLIGHTS and FARES and
write SQL commands for the questions (i) to (iv) and give outputs for
SQL queries (v) to (vi)
TABLE: FLIGHTS
FL_NO
STARTING
ENDING
NO_FLIGHTS
IC301
MUMBAI
DELHI
8
IC799
BANGALORE
DELHI
2
MC101
INDORE
MUMBAI
3
IC302
DELHI
MUMBAI
8
AM812
KANPUR
BANGALORE
3
IC899
MUMBAI
KOCHI
1
Databases and SQL
20
NO_STOPS
0
1
0
0
1
4
AM501
MU499
IC701
FL_NO
IC701
MU499
AM501
IC899
IC302
IC799
MC101
AIRLINES
Indian Airlines
Sahara
Jet Airways
Indian Airlines
Indian Airlines
Indian Airlines
Deccan Airlines
TABLE: FARES
FARE
6500
9400
13450
8300
4300
10500
3500
5
3
0
TAX%
10
5
8
4
10
10
4
(i)Display FL_NO and NO_FLIGHTS from KANPUR to BANGALORE from the table FLIGHTS.
(b) (i)
SELECT FL_NO,NO_FLIGHTS FROM FLIGHTS
WHERE STARTING=KANPUR AND ENDING=BANGALORE;
(1/2 Mark for using SELECT and FROM correctly)
(1/2 Mark for correct WHERE clause)
(ii) Arrange the contents of the table FLIGHTS in the ascending order of FL_NO.
(ii)
SELECT * FROM FLIGHTS ORDER BY FL_NO;
(1/2 Mark for using SELECT and FROM correctly)
(1/2 Mark for correct ORDER BY clause [ASC is optional])
(iii) Display the FL_NO and fare to be paid for the flights from DELHI to MUMBAI using the tables FLIGHTS
and FARES, where the fare to be paid=FARE+FARE*TAX%/100
(iii)
SELECT FLIGHTS.FL_NO, FARE+FARE*TAX/100
FROM FLIGHTS, FARES WHERE FLIGHTS.STARTING=DELHI AND
FLIGHTS.ENDING=MUMBAI AND FLIGHTS.FL_NO=FARES.FL_NO;
*Assuming TAX% as TAX
(Full 1 Mark for correctly attempting any part of 5 (b))
(iv) Display the minimum fare Indian Airlines is offering from the tables FARES.
(iv)
SELECT MIN(FARE) FROM FARES WHERE AIRLINES=INDIAN AIRLINES;
(1/2 Mark for using SELECT and FROM with MIN function correctly)
(1/2 Mark for correct WHERE clause)
(v) SELECT FL_NO, NO_FLIGHTS, AIRLINES FROM FLIGHTS, FARES WHERE STARTING = DELHI
AND FLIGHTS.FL_NO=FARES.FL_NO.
(v)
Databases and SQL
21
[6]
ID
101
107
114
109
105
117
111
130
NAME
SMITH
GEORGE
LARA
K GEORGE
JOHNSON
LUCY
BILL
MURPHY
TABLE : SALARY
ID
BASIC
101
12000
104
23000
107
32000
114
12000
109
42000
105
18900
130
21700
DEPT
ORTHOPEDIC
CARDIOLOGY
SKIN
MEDICINE
ORTHOPEDIC
ENT
MEDICINE
ORTHOPEDIC
TABLE : DOCTOR
SEX
EXPERIENCE
M
5
M
10
F
3
F
9
M
10
F
3
F
12
M
15
ALLOWANCE
1000
2300
4000
5200
1700
1690
2600
CONSULTATION
300
500
500
100
200
300
300
(i) Display NAME of all doctors who are in MEDICINE having more than 10
years experience from the table DOCTOR.
(i)
SELECT NAME FROM DOCTOR
WHERE DEPT = MEDICINE AND EXPERIENCE >10;
Databases and SQL
22
RecName
RecAddress
RecCity
R Bajpayee 5, Central Avenue
Kolkata
S Mahajan
116, A Vihar New
Delhi
H Singh
2A, Andheri East
Mumbai
P K Swamy B5, C S Terminus
Mumbai
S Tripathi
13, B1 D, Mayur Vihar New Delhi
B.RecName
H Singh
P K Swamy
5(a) What is the importance of a Primary Key in a table ? Explain with a suitable
example.
2
(a) The Primary Key is an attribute/set of attributes that identifies a tuple/ row/
record uniquely.
Example:
Rollnumber in the table STUDENT
OR
AccessionNumber in the table LIBRARY
OR
EmpNumber in the table EMPLOYEE
OR
PanNumber in the table INCOMETAX
OR
MemberNumber in the table MEMBER
OR
AccNumber in the table BANK
OR
Any other suitable example
(1 Mark for correct definition/explanation of Primary Key)
(1 Mark for suitable example)
(b) Consider the following tables Consignor and Consignee. Write SQL
commands for the statements (i) to (iv) and give outputs for SQL queries (v)
to (viii).
6
TABLE : CONSIGNOR
CnorlD
CnorName CnorAddress
City
ND01 R Singhal
24, ABC Enclave
New Delhi
ND02 Amit Kumar 123, Palm Avenue
New Delhi
MU15 R Kohli
5/A, South Street
Mumbai
MU50 S Kaur
27-K, Westend
Mumbai
TABLE : CONSIGNEE
CneelD
CnorlD
CneeName CneeAddress
CneeCity
MU05 ND01 Rahul Kishore
5, Park Avenue
Mumbai
ND08 ND02 P Dhingra
16/J, Moore Enclave New Delhi
KO19 MU15
A P Roy
2A, Central Avenue Kolkata
Databases and SQL
26
TABLE : CUSTOMER
(i) To display the details of those Customers whose City is Delhi
Ans:
SELECT * FROM CUSTOMER WHERE City=Delhi ;
( Mark for correct use of SELECT and FROM)
( Mark for correct use of WHERE clause)
(ii) To display the details of Items whose Price is in the range of 35000 to
55000 (Both values included)
Ans:
SELECT * FROM ITEM WHERE PRICE BETWEEN 35000 AND 55000;
OR
SELECT * FROM ITEM WHERE PRICE>=35000 AND PRICE<=55000;
( Mark for correct use of SELECT and FROM)
( Mark for correct use of WHERE clause)
371
(iii) To display the CustomerName, City from table Customer and ItemName
and Price from table Item, with their corresponding matching I-Id
Ans:
SELECT CustomerName, City, ItemName , Price
FROM CUSTOMER C, ITEM I WHERE I. I_Id=C.I_ID;
OR
SELECT CustomerName, City, ItemName, Price
FROM CUSTOMER, ITEM WHERE CUSTOMER.I_Id=ITEM.I_ID;
OR
SELECT C. CustomerName, C.City, I.ItemName, I.Price
Databases and SQL
30
TABLE: CLIENT
Answer:
Degree of a table is total number of attributes.
Cardinality of a table is total number of rows.
(1 mark for definition of Degree)
(1 mark for definition of Cardinality)
(b) Consider the following tables ACTIVITY and COACH. Write SQL commands for the statements
(i) to (iv) and give outputs for SQL queries (v) to (viii)
6
Table: ACTIVITY
ACode ActivityName
1001
1002
1003
1005
1008
Relay 100x4
High jump
Shot Put
Long Jump
Discuss Throw
Table: COACH
PCode Name
1
Ahmad
Hussain
2
Ravinder
3
Janila
4
Naaz
ParticipantsNu
m
16
10
12
12
10
PrizeMoney
10000
12000
8000
9000
15000
ScheduleDate
23-Jan-2004
12-Dec-2003
14-Feb-2004
01-Jan-2004
19-Mar-2004
ACode
1001
1008
1001
1003
(i)
To display the name of all activities with their Acodes in descending order.
Answer:
SELECT ActivityName, ACode FROM ACTIVITY ORDER BY Acode DESC;
( mark for correct SELECTion of columns)
( mark for correct use of ORDER BY)
(ii) To display sum of PrizeMoney for each of the Number of participants groupings (as shown in
column ParticipantsNum 10,12,16)
Answer:
SELECT SUM(PrizeMoney),ParticipantsNum FROM ACTIVITY GROUP BY
ParticipantsNum;
( mark for correct SELECTion of columns)
( mark for correct use of GROUP BY)
(iii)
To display the coachs name and ACodes in ascending order of ACode from the table
COACH
Answer:
SELECT Name, ACode FROM COACH ORDER BY ACode;
Databases and SQL
35
Number
2
2
4
2
4
Table: PLAYER
PCode Name
1
Nabi Ahmad
2
Ravi Sahai
3
Jatin
4
Nazneen
Gcode
101
108
101
103
(i)
Answer:
PrizeMoney
ScheduleDate
5000
23-Jan-2004
12000
12-Dec-2003
8000
14-Feb-2004
9000
01-Jan-2004
25000
19-Mar-2004
59000
( mark for correct output)
(viii) SELECT DISTINCT Gcode FROM PLAYER;
Answer:
101
103
108
( mark for correct output)
Item
Pen
Pencil
CD
Floppy
Eraser
Duster
Qty
560
780
450
700
300
200
10024
10090
10019
10009
10007
10020
10089
FCODE
F04
F02
F03
F01
TYPE
POLYSTER
COTTON
SILK
TERELENE
(2)
Item
Pen
Pencil
CD
Floppy
Eraser
Duster
Qty
560
780
450
700
300
200
PRICE MCODE
1250
M001
750
M004
1450
M002
850
M003
850
M002
1250
M003
850
M002
1450
M001
40
LAUNCHDATE
12-JAN-08
09-SEP-07
06-JUN-08
06-JUN-08
31-MAR-07
19-DEC-08
20-OCT-08
09-MAR-08
10009
10024
Table: MATERIAL
MCODE
MOO1
MOO2
MOO4
MOO3
TYPE
TERELENE
COTTON
POLYESTER
SILK
(i) To display DCODE and DESCRIPTION of each dress in ascending order of DCODE.
(ii) To display the details of all the dresses which have LAUNCHDATE in between 05-DEC-07 and 20-JUN-08
(inclusive of both the dates).
(iii) To display the average PRICE of all the dresses which are made of material with MCODE as M003
(iv) To display material-wise highest and lowest price of dresses from DRESS table. (Display MCODE of each
dress along with highest and lowest price).
(v) SELECT SUM(PRICE) FROM DRESS WHERE MCODE='M001';
(vi) SELECT DESCRIPTION, TYPE FROM DRESS, MATERIAL WHERE
DRESS.MCODE=MATERIAL.MCODE AND DRESS.PRICE>=1250;
(vii) SELECT MAX(MCODE) FROM MATERIAL;
(viii) SELECT COUNT(DISTINCT PRICE) FROM DRESS;
(i) To display DCODE and DESCRIPTION of each dress in ascending order of DECODE.
SQL> SELECT DCODE, DESCRIPTION FROM DRESS ORDER BY DCODE ASC;
(1 Mark for correct query)
( Mark for partially correct answer) :
DCODE
DESCRIPTION
------------------------10001 FORMAL SHIRT
10007 FORMAL PANT
10009 INFORMAL PANT
10012 INFORMAL SHIRT
10019 EVENING GOWN
10020 FROCK
10023 PENCIL SKIRT
10024 BABY TOP
10089 SLACKS
10090 TULIP SKIRT
10 rows selected.
Databases and SQL
41
1250
1450
850
1450
PRICE
MCODE LAUNCHDATE
--------------------M001 12-JAN-08
M002 06-JUN-08
M003 06-JUN-08
M001 09-MAR-08
(iii) To display the average PRICE of all the dresses which are made of material with MCODE as M003.
SQL> SELECT AVG(PRICE) FROM DRESS WHERE MCODE='M003';
(1 Mark for correct query)
( Mark for partially correct answer)
AVG(PRICE)
---------900
(iv) To display material-wise highest and lowest price of dresses from DRESS table. (Display MCODE of each
dress along with highest and lowest price).
Ans SELECT MCODE, MAX(PRICE), MIN (PRICE) FROM DRESS GROUP BY MCODE;
(1 Mark for correct query)
( Mark for partially correct answer)
MCOD
---M001
M002
M003
M004
MAX(PRICE)
---------1450
1450
1250
750
MIN(PRICE)
---------1250
850
650
750
TYPE
--------TERELENE
TERELENE
COTTON
COTTON
SILK
Item
Pen
Pencil
CD
Floppy
Eraser
Duster
Qty
560
780
450
700
300
200
Table: STOCK
Databases and SQL
44
Item
Ball Pen 0.5
Ball Pen 0.25
Gel Pen Premium
Gel Pen Classic
Eraser Small
Eraser Big
Sharpener Classic
Dcode
102
102
101
101
102
102
103
Qty
100
150
125
200
210
60
160
UnitPrice
16
20
14
22
5
10
8
StockDate
31-Mar-10
01-Jan-10
14-Feb-10
01-Jan-09
19-Mar-09
12-Dec-09
23-Jan-09
Table: DEALERS
Dcode
101
103
102
Dname
Reliable Stationers
Classic Plastics
Clear Deals
DCODE
---------101
103
102
102
102
101
102
7 rows selected.
(ii) To display ItemNo and Item name of those items from Stock table whose UnitPrice is more than Rupees 10.
Ans.:
SQL> SELECT ItemNo, Item FROM Stock WHERE UnitPrice>10;
ITEMNO ITEM
---------- -------------------5005 Ball Pen 0.5
5003 Ball Pen 0.25
5002 Gel Pen Premium
5006 Gel Pen Classic
(iii) To display the details of those items whose dealer code (Dcode) is 102 or Quantity in Stock (Qty) is more
than 100 from the table Stock.
Ans.:
SQL> SELECT * FROM Stock WHERE Dcode=102 OR Qty>100 ;
Databases and SQL
45
Ans.:
COUNT(DISTINCTDCODE)
--------------------3
(ii) SELECT Qty*UnitPrice FROM Stock WHERE ItemNo=5006;
Ans.:
QTY*UNITPRICE
------------4400
(iii) SELECT Item, Dname FROM Stock S, Dealers D WHERE S.Dcode=D.Dcode AND ItemNo=5004;
Ans.:
ITEM
DNAME
-------------------- -------------------Eraser Big
Clear Deals
(iv) SELECT MIN(StockDate) FROM Stock;
Ans.:
MIN(STOCKDATE)
--------Databases and SQL
46
Q: Write a query to display the total unit price, average unit price, highest
unit price, lowest unit price, number of unit prices.
***************