Sie sind auf Seite 1von 47

OUR OWN HIGH SCHOOL, AL WARQAA

Computer Science Workshop : Grade 12


/
SQL
(Questions from CBSE Board Exam- from 1998 to 2010)
YEAR: 1998(Outside Delhi)
Q 5 (a) What is need for normalization? Define First, Second and Third Normal Form.
Ans. Need for Normalization: The basic objective of normalization is to reduce redundancy, which means
that data to be stored only once. Because storing data many times lead to wastage of space and increase
access time. So relation/table are to be normalized so that we can alter them at any time without doing
much changes.
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.
Second Normal Form: A table / relation is said to be in Second Normal Form (2NF) if and only if it is in
First Normal Form and every non-key attribute is functionally dependent on the Primary Key.
Third Normal Form: A table / relation is said to be in Third Normal Form (1NF) if and only if it is in
Second Normal From and every non-key attribute is non-transitively dependent upon the primary key.
NOTE : Write SQL commands for(b) to (g) and write the output for (h) on the basis of table HOSPITAL.
TABLE : HOSPITAL
No Name
Age
Department Datofadm
Charges
Sex
1 Sandeep
65
Surgery
23/02/98
300
M
2 Ravina
24
Orthopedic
20/01/98
200
F
3 Karan
45
Orthopedic
19/02/98
200
M
4 Tarun
12
Surgery
01/01/98
300
M
5 Zubin
36
ENT
12/02/98
250
M
6 Ketaki
16
ENT
24/02/98
300
F
7 Ankita
29
Cardiology
20/02/98
800
F
8 Zareen
45
Gynecology
22/02/98
300
F
9 Kush
19
Cardiology
13/01/98
800
M
10 Shaliya
31
Nuclear
19/02/98
400
M
Medicine
(b) To show all information about the patients of cardiology department.
Ans: SELECT * FROM hospital WHERE department=Cardiology;
(c ) To list the names of female patients who are in orthopedic dept.
Ans: SELECT name FROM hospital WHERE sex=F AND department=Orthopedic;
(d) To list names of all patients with their date of admission in ascending order.
Ans.: SELECT name, dateofadm FROM hospital ORDER BY dateofadm;
(e) To display Patients Name, Charges, age for male patients only.
Ans: SELECT name, charges, age FROM hospital WHERE sex=M;
(f) To count the number of patients with age >20.
Ans.: SELECT COUNT(age) FROM hospital WHERE age>20;
Databases and SQL
1

OUR OWN HIGH SCHOOL, AL WARQAA


Computer Science Workshop : Grade 12
(g) To insert a new row in the HOSPITAL table wit the following .
11,mustafa,37,ENT,(25/02/98},250,M
Ans.: INSERT INTO hospital VALUES (11, Mustafa, 37, ENT, 25/02/98, 250, M);
(h) Give the output of following SQL statement:
(i) Select COUNT(distinct departments) from HOSPITAL;
Ans: COUNT(DISTICNTDEPARTMEN)
-------------------------------------------6
(ii)
Select Max (Age) from HOSPITAL where SEX = M;
Ans: MAX(AGE)
--------------65
(iii)
Select AVG(Charges) from HOSPITAL where SEX = F;
Ans.: AVG(CHARGES)
---------------------400
(iv)
Select SUM(Charges) from HOSPITAL where Datofadm<{12/02/98}
Ans.: SUM(CHARGES)
---------------------1300
YEAR 1998(Delhi)
5(a) What is a relation? What is the difference between a tuple and an attribute?
Note: Write SQL commands for (b) to (g) and write the output for (h) on the basis of table HOSPITAL.
Table: HOSPITAL
No
1
2
3
4
5
6
7
8
9
10

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

(b) To select all the information of patients of Cardiology department.


(c) To list the names of female patients who are in ENT department.
(d) To list names of all patients with their date of admission in ascending order.
(e) To display patients name, charges, age for only female patients.
(f) To count the number of patients with age<30.
(g) To insert a new row in the HOSPITAL table with the following data:
11, Aftab, 24, Surgery, {25/02/98}, 300, M
(h) Give the output of the following SQL statements:
(i) SELECT COUNT(DISTINCT charges) FROM hospital;
(ii) SELECT MIN(age) FROM hospital WHERE sex=F;
(iii)
SELECT SUM(charges) FROM hospital WHERE department=ENT;
(iv)
SELECT AVG(charges) FROM hospital WHERE dateofadm<{12/02/98};
Databases and SQL
2

Sex
M
F
M
M
M
F
F
F
M
F

OUR OWN HIGH SCHOOL, AL WARQAA


Computer Science Workshop : Grade 12
Que 2 --YEAR : 1999
5.a) What is normalization ? Define third normal form
Ans.: Normalization: The normalization is the process of transformation of the conceptual schema
(logical data structure) of the database into a computer representable from..
Third Normal Form: A table / relation is said to be in Third Normal Form (1NF) if and only if it is in
Second Normal From and every non-key attribute is non-transitively dependent upon the primary key.
Given the following Employee Form :
No Name
Age
Department

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

(c ) To list the names of female employees who are in Science branch


Ans.: SELECT name FROM employee WHERE sex= F AND branch= Science;
(d) To list the names of all employees with their date of retirement in ascending order.
Ans.: SELECT name, dateofrtd FROM employee ORDER BY dateofrtd;
(e) To display Employees name , Salary ,Age for male employees only
Ans.: SELECT name, salary, age FROM employee WHERE sex= M;
(f) To count the number of employees with AGE > 33.
Ans.: SELECT COUNT(age) FROM employee WHERE age>33;
(g) To insert a new row in the EMPLOYEE table with the following data:
9,Rohit,46,language,{22/06/98},2300,M
Ans.: INSERT INTO employee VALUES (9, Rohit, 46, Language,22/06/98,2300, M);
(h) Give the output of the following SQL statements:
(i) Select COUT(distinct department) from EMPLOYEE;
Ans: COUNT(DISCTINCTDEPARTMENT)
-----------------------------------------------4
(ii) Select MAX(Age) from EMPLOYEE where SEX =F;
Ans.: MAX(AGE)
--------------41
Databases and SQL
3

OUR OWN HIGH SCHOOL, AL WARQAA


Computer Science Workshop : Grade 12
(v)
Select AVG(Fee) form EMPLOYEE where SEX = M;
Ans.: No such column Fee
(iv) Select SUM(Fee) from EMPLOYEE where Dateofrtd<{01/01/98};
Ans.: No such column Fee
Que 3 YEAR : 2000
(a) Differentiate between SQL commands DROP TABLE and DROP VIEW . Define Second Normal
Form.
Ans.:
Drop Table
Drop View
Removes the table physically from the storage
Deletes the view from the database.
device.
The condition for dropping a table is that it must
Deletion of the row is not necessary.
be an empty table.
Second Normal Form: A table / relation is said to be in Second Normal Form (2NF) if and only if it is in
First Normal Form and every non-key attribute is functionally dependent on the Primary Key.
Note: Write SQL commands for(b) to (e) and write the outputs for (f) on the basis of table GRADUATE.
TABLE : GRADUATE
S No NAME
Stipend Subject
Average
Div
1 Karan
400
Physics
68
1
2 Divakar
450
Computers
68
1
3 Divya
300
Chemistry
62
2
4 Arun
350
Physics
63
1
5 Sabina
500
Mathematics
70
1
6 John
400
Chemistry
55
2
7 Robert
250
Physics
64
1
8 Rubina
450
Mathematics
68
1
9 Vikas
500
Computers
62
1
10 Mohan
300
Mathematics
57
2
(b) List the names of those students who obtained DIV 1 sorted by NAME .
Ans.: SELECT name FROM graduate WHERE div=1 ORDER BY name;
(c )Display a report, listing NAME , STIPEND , SUBJCT and amount of stipend received in a year
assuming that the STIPEND is paid every month.
Ans.: SELECT name, stipend, subject, stipend *12 FROM graduate;
(d) To insert a new row in the GRADUATE table :
11,KAJOL,300, COMPUTERS,75,1
Ans.: INSERT INTO graduate VALUES (11, Kajol, 300, Computers, 75,1);
(h) Give the output of the following SQL statements based on table GRADUATE :
(i) Select MIN(AVERAGE ) from GRADUATE where SUBJECT=PHYSICS;
Ans. MIN(AVERAGE)
---------------------63
Databases and SQL
4

OUR OWN HIGH SCHOOL, AL WARQAA


Computer Science Workshop : Grade 12
(ii)Select SUM(STIPEND) from GRADUATE where DIV=1;
Ans.: SUM(STIPEND)
--------------------1000
(iii)Select AVG(STIPEND) from GRADUATE where AVERAGE >=65;
Ans.: AVG(STIPEND)
---------------------450
(vi)
Select COUNT( distinct SUBJECT) from GRADUATE;
Ans.: COUNT(DISCTINCTSUBJECT)
-----------------------------------------4
Assume that there is one more table GUIDE in the database as shown below:
Table : GUIDE
MAINAREA
ADVISOR
PHYSICS
VINOD
COMPUTER SC ALOK
CHEMISTRY
RAJAN
MATHEMATICS MAHESH
What will be the output of the following query:
SELECT NAME, ADVISOR
FROM
GRADUATE, GUIDE
WHERE
SUBJECT=MAINAREA;
Ans.:
NAME
ADVISOR
--------------------Karan
VINOD
Divakar
ALOK
Divya
RAJAN
Arun
VINOD
Sabina
MAHESH
John
RAJAN
Robert
VINOD
Rubina
MAHESH
Vikas
ALOK
Mohan
MAHESH
Que 4 YEAR : 2001
(a) When is a relation said to be in second normal form?
Ans.: Second Normal Form: A table / relation is said to be in Second Normal Form (2NF) if and only if it
is in First Normal Form and every non-key attribute is functionally dependent on the Primary Key.
(b) Write SQL commands for (I) to ( vii) on the basis of the table SPORTS
S no. Class
Name
Game1
Grade1 Game2
10
7 Sameer
Cricket
B
Swimming
11
8 Sujit
Tennis
A
Skating
12
7 Kamal
Swimming
B
Football
13
7 Veena
Tennis
C
Tennis
14
9 Archana
Basketball
A
Cricket
15
10 Arprit
Cricket
A
Athletics
Databases and SQL
5

Grade2
A
C
B
A
A
C

OUR OWN HIGH SCHOOL, AL WARQAA


Computer Science Workshop : Grade 12
(j) Display the names of the students who have grade C in either Game1 or Game2 or both.
Ans.: SELECT name FROM sports WHERE grade1= C OR grade2= C;
(ii)Display the number of students getting grade A in Cricket.
Ans.: SELECT COUNT(*) FROM sports WHERE greade1= A or grade2= A;
(iii)Display the names of the students who have same game for both Game1 and Game2.
Ans.: SELECT name FROM sports WHERE game1=game2;
(iv)Display the games taken up by the students , whose name starts with A.
And.: SELECT game1,game2 FROM sports WHERE name LIKE A%;
(v)
Add a new column named Marks.
Ans.: ALTER TABLE sports ADD (marks NUMBER(2));
(vi)

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

OUR OWN HIGH SCHOOL, AL WARQAA


Computer Science Workshop : Grade 12
(c) To select all the information of teacher in computer department.
Ans.: SELECT * FROM teacher WHERE department= Computer;
(d) To list the name of female teachers in History department.
Ans.: SELECT * FROM teacher WHWRE sex= F AND department = History;
(e) To list all names of teachers with date of admission in ascending order.
Ans.: SELECT name, dateofjoining FROM teacher ORDER BY dateofjoining;
(f) TO display Teachers name, Department, and Salary of female teacher.
Ans.: SELECT name, department, salary FROM teacher WHERE sex= F;
(g) To count the number of items whose salary is less than 10,000.
Ans. SELECT COUNT(*) FROM teacher WHERE salary<10000;
(h) To insert a new record in the Teacher table with thefollowing data:
8,Mersha,computer,{1/1/2000},12000,m.
Ans.: INSERT INTO teacher VALUES (8, Mersha, Computer, 01/01/2000,12000, M);
(i) Give the output of the following SQL command:
1.SELECT MIN(DISTINCT Salary) FROM Teacher;
Ans.: MIN(DISTINCTSALARY)
--------------------------------8000
2. SELECT MIN (Salary) FROM Teacher WHERE Sex = M;
Ans.: MIN(SALARY)
-------------------8000
3. SELECT SUM(Salary) FROM Teacher WHERE Department = HISTORY;
Ans.: SUM(SALARY)
--------------------17000
4. SELECT AV(Salary) FROM Teacher WHERE Dateofjoining < {1/1/98}
Ans. AVG(SALARY)
-------------------11250
Que 6YEAR 2003
(a) What is primary key in a table? Define first normal form.
Ans.: Primary Key: A Primary Key is a set of one or more attributes that can uniquely identify tuples /
records within a relation / table.
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.
NOTE : Write SQL commands for(b) to (g) and write the outputs for(h) on the basis of table
INTERIORS
TABLE : INTERIORS
No. Itemname
1 Red_rose

Type
Double Bed

Dateofstock
23/02/02

Databases and SQL


7

Price
32000

Discount
15

OUR OWN HIGH SCHOOL, AL WARQAA


Computer Science Workshop : Grade 12
2 Soft touch
Baby cot
20/01/02
9000
10
3 Jerry's home Baby cot
19/02/02
8500
10
4 Rough wood Office Table
01/01/02
20000
20
5 Comfort zone Double Bed
12/01/02
15000
20
6 Jerry look
Baby cot
24/02/02
7000
19
7 Lion king
Office Table
20/02/02
16000
20
8 Royal tiger Sofa
22/02/02
30000
25
9 Park sitting Sofa
13/12/01
9000
15
10 Dine
Dining Table
19/02/02
11000
15
Paradise
11 White wood Double Bed
23/03/03
20000
20
12 James 007
Sofa
20/02/03
15000
15
13 Tom look
Baby cot
21/02/03
7000
10
(b) TO show all information about the Sofas from the INTERIORS table
Ans.: SELECT * FROM interiors WHERE type= Sofa;
(c) To list the ITEMNAME which are priced at more than 10000 from the INTERIORS TABLE;
Ans.: SELECT itemname FROM interiors WHERE price>10000;
(d) To list ITEMNAME and TYPE of those items, in which DATEOFSTOCK is be 22/01/02 from the
INTERIORS table in descending order of ITEMNAME.
Ans.: SELECT itemname, type FROM interiors WHERE dateofstock<22/01/02 ORDER BY itemname
DESC;
(e) TO display ITEMNAME and DATEOFSTOCK of items whose discount is more than 15
Ans. SELECT itemname, dateofstcok FROM interiors WHERE discount>15;
(f) TO count the number of items, whose type is DOUBLE BED from INTERIORS table
Ans.: SELECT COUNT(type) FROM interiors WHERE type= Double Bed;
(g) TO insert a new row in the NEWONES table with the following data:
14, True Indian , Office Table,{28/03/03},15000,20
Ans.: INSERT INTO interiors VALUES (14, True Indian, Office Table, 28/03/03, 15000, 20);
(h) Give the output of following SQL statements :
NOTE : Outputs of the below mentioned queries should be based on the original data given in both the
tables i.e. without considering the insertion done in (g) part of this question.
(i) Select COUNT(distinct TYPE) from INTERIORS;
Ans.: COUNT(DISTICNTTYPE)
---------------------------------5
(ii) Select AVG(DISCOUNT) from INTERIORS where TYPE = Baby Cot;
Ans.: AVG(DISCOUNT)
----------------------13
(iii) Select SUM(Price) from INTERIORS where DATOFSTOCK < ( 12/02/02};
Ans.: SUM(PRICE)
----------------53000
Databases and SQL
8

OUR OWN HIGH SCHOOL, AL WARQAA


Computer Science Workshop : Grade 12
Year : 2004
5(a) What is do you understand by normalization? Define First normal form
Ans.: Normalization: The normalization is the process of transformation of the conceptual schema
(logical data structure) of the database into a computer representable from..
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.
Table: Books
Book_Id Book_Name
F001
The Tears
F002

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

Write SQL queries fro (b) to (g):


b) To show Book name, Author Name and price of books of EPB publishers.
Ans.: SELECT Book_name, author_name, price FROM books WHERE publishers= EPB;
c) To list the name of books of Fiction type
Ans.: SELECT book_name FROM books WHERE type= Fiction;
d) To display the name and price of the books in descending order of their price.
Ans.: SELECT book_name, price FROM books ORDER BY price DESC;
e) To increase the price of all books of First Publ. by 50
Ans.: UPDATE books SET price=price+50 WHERE publishers = First Publ.;
f) To display the Book_Id, Book_Name and Quantity_Issued for all books which have been issued. (The
query will require contents from both tables)
Ans.: SELECT books.Book_id, book_name, quantity_issued FROM books, issued WHERE
books.book_id = issued.book_id;
g) To insert a new row in the table Issued having the following data:
F001, 4
Ans.: INSERT INTO issued VALUES (F002,4);
h) Give the output of the following queries based on the above tables.
i) Select count(distict publichers) from books;
i) COUNT(DISTINCTPUBLISHERS)
------------------------------------------Databases and SQL
9

OUR OWN HIGH SCHOOL, AL WARQAA


Computer Science Workshop : Grade 12
3
ii) Select sum(price) from books where quantity>5;
ii) SUM(PRICE)
----------------1350
iii) Select book_name, author_name from books where price<500;
iii) BOOK_NAME
AUTHOR_NAME
---------------------------------------My First C++
Brain & Brooks
C++ Brainworks
A.W. Rossaine
Fast Cook
Lata Kapoor
iv) Select count(*) from books;
iv)
COUNT(*)
------------5
Que 7CBSE 1
(a) What is the purpose of normalization? Define primary key.
Answer: Purpose of Normalization:
It reduces data redundancies
It helps in eliminating data anomalies
It helps in linking tables
Primary Key: It is set of one or more attributes that can uniquely identify tuples or records within a table
or relation.
NOTE: Write SQL commands for (b) to(g) and write the outputs for(h) on the basis of tables
FURNITURE.
TABLE : 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
Double bed
12/01/02
25000
25
Zone
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
Dining table
19/02/02
11500
25
paradise
11 WoodComfor Double Bed
23/03/03
25000
25
t
12 Old Fox
Sofa
20/02/03
17000
20
13 Micky
Baby cot
21/02/03
7500
15
(b) To show all information about the Baby cots from the FURNITURE table
SELECT * FROM furniture WHERE type= Baby cot;
Databases and SQL
10

OUR OWN HIGH SCHOOL, AL WARQAA


Computer Science Workshop : Grade 12
(c) To list the ITEMNAME which are priced at more than 15000 from the FURNITURE table.
1
SELECT itemname FROM furniture WHERE price>15000;
(d) To list ITEMNAME and TYPE of those items, in which date of stock is before 22/01/02 from the
FURNITURE table in the descending order of ITEMNAME
Select itemname, type from furniture where dateofstock < {22/01/02} order by itemname;
(e) To display ITEMNAME and DATAOFSTOCK of those items, whose TYPE is Sofa from
FURNITURE table
Select itemname , dateofstock from furniture where type=Sofa;
(f) To insert a new row in the ARRIVALS table with the following data:
14,Velvet touch , Double Bed,{25/03/03},25000,30
Insert into furniture values (14, Velvet touch, Double Bed, {25/03/03}, 25000, 30);
(g) Give the output of following SQL statement:
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 (g) part of this question
(j) Select COUNT (distinct TYPE) from FURNITURE;
COUNT(DISTINCT TYPE)
-----------------------------------5
(ii) Select MAX(DISCOUNT) from FURNITURE ;
MAX(DISCOUNT)
-----------------------30
(iii) Select AVG(DISCOUNT) from FURNITURE where TYPE = Baby cot;
AVG(DISCOUNT)
-----------------------17.5

(iv) Select SUM(Price) from FURNITURE where DATEOFSTOCK<{12/02/02}


SUM(PRICE)
-----------------

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

OUR OWN HIGH SCHOOL, AL WARQAA


Computer Science Workshop : Grade 12
NOTE: Write SQL commands for (b) to (g) and write the outputs for (h) on the basis of tables
INTERIORS and NEWONES
The rest as same as question no. 6 .
(SAME AS BOVE)
CBSE-I: 2004
(a) What do you understand by Degree and Cardinality of a table?
Ans: Degree of a table is total number of attributes or fields or columns.
Cardinality of a table is total number of rows/records/tuples.
(b). Consider the following tables ACTIVITY and COACH.
Write SQL commands for the statements (i) to (iv) and give the
The outputs for the SQL queries (v) to (viii)
Table: ACTIVITY
ACode
ActivityName

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

(i) To display the name of all activities with their Acodes in


descending order.
Ans. SELECT ActivityName, Acode FROM activity ORDER
BY Acode DESC;
(ii) To display sum of prizemoney for each of the number of
participants groupings (as shown in column ParticipantsNum 10,12,16)
Ans.: SELECT SUM(PrizeMoney), ParticipantsNum FROM
activity GROUP BY ParticipantsNum;
(iii) To display the coachs name and ACodes in acending order of
ACode from the table COACH.
Ans: SELECT Name,ACode FROM coach ORDER BY ACode;
(iv) To display the content of the Activity table whose ScheduleDate
is earlier than 01/01/2004 in ascending order of ParticipantsNum
Ans: SELECT * FROM activity WHERE ScheduleDate<{01/01/2004}
Databases and SQL
12

OUR OWN HIGH SCHOOL, AL WARQAA


Computer Science Workshop : Grade 12
ORDER BY ParticipantsNum;
(v) SELECT COUNT(DISTINCT ParticipantsNum) FROM Activity;
Ans: 3
(vi) SELECT MAX(ScheduleDate), MIN(ScheduleDate) FROM
activity;
MAX(ScheduleDate) MIN(ScheduleDate)
--------------------------- -------------------------19/03/2004
12/12/2003
(vii) SELECT SUM(PrizeMoney) FROM activity;
SUM(PRIZEMONEY)
---------------------------54000
(viii) SELECT DISTINCT ParticipantsNum FROM activity;
DISTINCTPRTICIPANTNUM
--------------------------------------16
10
12

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

Databases and SQL


13

1
2
3
4

OUR OWN HIGH SCHOOL, AL WARQAA


Computer Science Workshop : Grade 12
Nabi Ahmad
101
Ravi Sahai
108
Jatin
101
Nazneen
103

(i) To display the name of all Games with their Gcodes.


SELECT GameName, Gcode FROM games;
(ii) To display details of those games which are having prizemoney more than 7000.
SELECT * FROM games WHERE PrizeMoney>7000;
(iii) To display the contents of the GAMES table in ascending order of ScheduleDate
SELECT * FROM games ORDER BY ScheduleDate;
(iv) To display sum of PrizeMoney for each of the number of participation.
SELECT SUM(PrizeMoney), Number FROM games GROUP BY number;
(v) SELECT COUNT(DISTINCT number) FROM games;
COUNT(DISTCINT)
-------------------------2
(vi) SELECT MAX(SheduleDate), MIN(ScheduleDate) FROM games;
MAX(SHEDULEDATE) MIN(SCHEDULEDATE)
------------------------------- --------------------------------19-Mar-2004
12-Dec-2003
(vii) SELECT SUM(PrizeMoney) FROM games;
SUM(PRIZEMONEY)
----------------------------59000

(viii) SELECT DISTICNT gcode FROM player;


DISTICNT GOCDE
------------------------101
108
103
Year: 2005 (Outside Delhi)

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

OUR OWN HIGH SCHOOL, AL WARQAA


Computer Science Workshop : Grade 12
OR
Candidate Key: The attribute (Column) or set of attributes (Columns),
which are capable of acting as candidate for primary key.
Cardinality of a relation: Number of rows in a table form cardinality of a
relation.
(1 Mark each for giving correct definition)
OR
(1 Murk each for explaining the concept using suitable example)
(b)Consider the following tables WORKERS and DESIG. Write SQL.com.mands for the statements (i) to
(iv) and give outputs of SQL queries (v) to (viii)
DESIG
W_ID

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

440 U.S. 110

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

842 Vine Ave.


9 Fifth Cross
12 Moore Street
121 Harrison St.
11 Red Road

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

OUR OWN HIGH SCHOOL, AL WARQAA


Computer Science Workshop : Grade 12
( Mark for correct SELECT FROM)
( Mark for correct WHERE clause)

(ii) To display the content of WORKERStabieiri ascending order of LASTNAME.


(ii) SELECT * FROM WORKERS ORDER BY LASTNAME;
( Mark for correct SELECT FROM)
( Mark for correct ORDER BY clause)
(iii) To display the Firstname, Lastname, and Total Salary of ail Clerks from
the tables WORKERS and DESIG, where Total Salary is calculated as Salary. + Benefits.
(iii) SELECT FIRSTNAME, LASTNAME, SALARY+BENEFITS
FROM WORKERS.DESIG WHERE DESIGNATION=CLERK
.
AND WORKERS,W_ID=DESIG
W_ID;
OR
SELECT FIRSTNAME,LASTNAME,SALARY+BENEFITS AS
TOTAL SALARY FROM WORKERS.DESIG WHERE
DESIGNATION=CLERK AND
.
WORKERS.W_ID=DESIG
W_ID;
( Mark for correct SELECT FROM)
( Mark for correct WHERE clause)
(iv) To display the Minimum salary am~mg Managers and Clerks from. the table
DESIG.
(iv) SELECT MIN(SALARY), DESIGNATION FROM DESIG WHERE
DESIGNATION IN ('Manager'.'Clerk') GROUP BY DESIGNATION;
OR
SELECT MIN(SALARY), DESIGNATION FROM DESIG WHERE
DESIGNATION= Manager OR DESIGNATION='Clerk' GROUP BY
DESIGNATION;
OR
SELECT MIN(SALARY) FROM DESIG WHERE DESIGNATION=
Manager OR DESIGNATION='Clerk';
OR
SELECT MIN(SALARY) FROM DESIG WHERE DESIGNATION IN
(Manager,Clerk);
( Mark for correct SELECT FROM)
( Mark for correct MIN function and WHERE clause)
(v) SELECT FIRSTNAME, SALARY
FROM WORKERS, DESIG
WHERE DESIGNATION = 'Manager' AND workers.w-id=desig.w-id;
(v)
Databases and SQL
16

OUR OWN HIGH SCHOOL, AL WARQAA


Computer Science Workshop : Grade 12
FIRSTNAME
SALARY
Sam
75000
Manila
70000
George
75000
( Mark for the correct output)
(vi) Select count(distinct designation) from design;
(vi)
COUNT(DISTINCT DESIGNATION)
4
( Mark for the correct output)
(vii) select designation, sum(salary) from design
group by designation having count(*)<3;
(vii)
DESIGNATION SUM(SALARY)
Director
85000
Salesman
60000
( Mark for the correct output)
(viii) select sum( benefits) from design where
designation=Salesman;
(viii)
( Mark for mentioning the error)
OR
( Mark for attempting this part of the question)
OR
( Mark for correctly attempting any two parts of the SQL question)
Year: 2005 (Delhi)

5(a) What do you understand by the terms


Primary Key and Degree of a relation in
relational database?

(a) Primary Key: The attribute (Column) or set of


attributes (Columns) which is used to identify
a tuple/row uniquely are known as Primary Key.
Degree of a relation: Number of attribute or column
in a table form cardinality of a relation.
[1 Mark each for giving correct definition]
OR
[1 Mark each for explaining the concept using
suitable example]
Databases and SQL
17

OUR OWN HIGH SCHOOL, AL WARQAA


Computer Science Workshop : Grade 12
(b)Consider the following tables EMPLOYEES and
EMPSALARY. Write SQL
commands for the statements (i) to (iv) and give
outputs for SQL queries (v) to (viii). 6
EMPLOYEES
EMPID
010
105
152
215
244
300
335
400
441

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

OUR OWN HIGH SCHOOL, AL WARQAA


Computer Science Workshop : Grade 12
(iii) To display the Firstname, Lastname, and Total Salary of all
Managers from
the tables EMPLOYEES and EMPSALARY, where Total Salary is calculated as
Salary + Benefits.
(iii)
Select FIRSTNAME, LASTNAME, SALARY From EMPLOYEES,
EMPSALARY
Where EMPLOYEES.EMPID=EMPSALARY.EMPID;
[
Marks for each part (here parts are separated into
lines for
convenience) of correct SQL Command]

(iv) To display the Maximum salary among Managers and


Clerks from the table EMPSALARY.
(iv)
Select Max(SALARY) From EMPSALARY
Where DESIGNATION = Manager OR DESIGNATION =
Clerk;
[ Marks for each part (here parts are separated into
lines for
convenience) of correct SQL Command]

(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

OUR OWN HIGH SCHOOL, AL WARQAA


Computer Science Workshop : Grade 12
COUNT (DISTINCT DESIGNATION)
4
Note: Heading is Optional
[ Mark for correct result]
(viI)
SELECT DESIGNATION, SUM(SALARY)
FROM EMPSALARY
GROUP BY DESIGNATION HAVING COUNT(*)>2;
(vii)
DESIGNATION SUM(SALARY)
Manager 215000
Note: Heading is Optional
Clerk 135000
[ Mark fdr correct result]

(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

OUR OWN HIGH SCHOOL, AL WARQAA


Computer Science Workshop : Grade 12
DELHI
TRIVANDRUM
1
MUMBAI
MADRAS
3
DELHI
AHMEDABAD
4

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

OUR OWN HIGH SCHOOL, AL WARQAA


Computer Science Workshop : Grade 12
FL_NO
NO_FLIGHTS
AIRLINES
IC302
8
Indian Airlines
AM501
1
Jet Airways
IC701
4
Indian Airlines
(1 Mark for correct output, Ignore First header line)
(vi) SELECT COUNT(DISTINCT ENDING) FROM FLIGHTS.
(vi) 7
(1 Mark for correct output)

[6]

YEAR 2006 (DELHI)


5 (a) What is an Alternate Key ?
2
(a) Candidate key(s), which is not selected as Primary Key, is known as
Alternate key(s).
(2 marks for any equivalent correct definition)
(b) Study the following tables DOCTOR and SALARY and write SQL commands
for the questions (i) to (iv) and give outputs for SQL queries (v) to (vi): 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

OUR OWN HIGH SCHOOL, AL WARQAA


Computer Science Workshop : Grade 12
( mark for correct Select statement)
( mark for correct Where clause)
(ii) Display the average salary of all doctors working in ENT department using
the tables DOCTOR and SALARY. Salary = BASIC + ALLOWANCE
(ii)
SELECT AVERAGE(S.BASIC + S.ALLOWANCE)
FROM DOCTOR D, SALARY S
WHERE D.DEPT = ENT AND D.ID = S.ID;
OR
SELECT AVERAGE(BASIC + ALLOWANCE)
FROM DOCTOR, SALARY
WHERE DEPT = ENT AND DOCTOR.ID = SALARY.ID;
(1/2 mark for correct Select statement)
(1/2 mark for correct Where clause)
OR
(1 mark for students who have correctly attempted any two parts of Q5b)
(iii) Display the minimum ALLOWANCE of female doctors,
(iii)
SELECT MIN(S.ALLOWANCE)
FROM DOCTOR D, SALARY S
WHERE D.SEX = F AND D.ID = S.ID;
OR
SELECT MIN(ALLOWANCE)
FROM DOCTOR, SALARY
WHERE SEX = F AND DOCTOR.ID = SALARY.ID;
( mark for correct Select statement)
( mark for correct Where clause)
(iv) Display the highest consultation fee among all male doctors,
(iv)
SELECT MAX(S.CONSULTATION)
FROM DOCTOR D, SALARY S
WHERE D.SEX = M AND D.ID = S.ID;
OR
SELECT MAX(CONSULTATION)
FROM DOCTOR , SALARY
WHERE SEX = M AND DOCTOR.ID = SALARY.ID;
(1/2 mark for correct Select statement)
(1/2 mark for correct Where clause)
(v) SELECT count(*) from DOCTOR where SEX = F
(v)
4
(1 mark for correct answer)
(vi) SELECT NAME, DEPT, BASIC from DOCTOR, SALARY
where DEPT = ENT and DOCTOR.ID = SALARY.ID
Databases and SQL
23

OUR OWN HIGH SCHOOL, AL WARQAA


Computer Science Workshop : Grade 12
(vi)
NAME
DEPT BASIC
John ENT
12000
(1 mark for correct answer)
YEAR 2007 (OUTSIDE DELHI)
5(a) Differentiate between primary key and alternate key. 2
(a) All candidate keys, which are not the primary key of the table are called the
alternate keys.
OR
Primary Key:
An attribute/ column used to identify each record in a table
Alternate Key:
All such attributes/columns, which can act as a primary key
but are not the primary key in a table.
(2 Mark for any valid difference/relation between Primary Key and
Alternate Key)
OR
(1 Mark for correct explanation of Primary Key)
(1 Mark for correct explanation of Alternate Key)
(b) Consider the following tables. Write SQL commands for the statements
(i) to (iv) and give outputs for SQL queries (v) to (viii) 6
TABLE:SENDER
SenderlD
SenderName SenderAddress
SenderCiry
ND01 R Jain
2, ABC Appts
New Delhi
MU02 H Sinha
12, Newtown
Mumbai
MU15 S Jha
27/A, Park Street
Mumbai
ND50 T Prasad
122-K, SDA
New Delhi
TABLE : RECIPIENT
RecID SenderlD
KO05 ND01
ND08 MU02
MU19 ND01
MU32 MU15
ND48 ND50

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

(i) To display the names of all Senders from Mumbai


(b) (i)
SELECT SenderName from Sender WHERE City =
Mumbai;
(ii) To display the RecID), SenderName, SenderAddress, RecName,
Databases and SQL
24

OUR OWN HIGH SCHOOL, AL WARQAA


Computer Science Workshop : Grade 12
RecAddress for every Recipient
(ii)
SELECT R.RecID, S.SenderName, S.SenderAddress,
R.RecName, R.RecAddress FROM Sender S,
Recipient R
WHERE S.SenderID = R.SenderID;
(iii) To display Recipient details in ascending order of RecName
(iii)
SELECT * FROM Recipient ORDER BY RecName;
(iv) To display number of Recipients from each city
(iv)
SELECT COUNT(*) FROM Recipient GROUP BY RecCity

(v) SELECT DISTINCT SenderCity FROM Sender;


(v)
SenderCity
Mumbai
New Delhi
(vi) SELECT A. SenderName, B.RecName
FROM Sender A, Recipient B
WHERE A. SenderlD = B.SenderlD AND B.RecCity = Mumbai;
(vi)
A.SenderName
R Jain
S Jha

B.RecName
H Singh
P K Swamy

(vii) SELECT RecName, RecAddress


FROM Recipient
WHERE RecCity NOT IN (Mumbai, Kolkata);
(vii)
RecName
RecAddress
S Mahajan
116, A Vihar
S Tripathi
13, Bl D, Mayur Vihar
(viii) SELECT RecID, RecName
FROM Recipient
WHERE SenderID=MU02' ORSenderID=ND50';
(viii)
RecID RecName
ND08 S Mahajan
ND48 S Tripathi
(Part (i) to (iv) - 1 Mark for each correct query)
Databases and SQL
25

OUR OWN HIGH SCHOOL, AL WARQAA


Computer Science Workshop : Grade 12
(Part (v) to (viii) - Marks for each correct output)
Note:
Column headings for the output questions to be ignored.
Since in part (iv) the fieldname RecCity is not mentioned
specifically, so full 1 mark to be given if any part of 5 (b) is
answered correctly.

YEAR 2007 (DELHI)

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

OUR OWN HIGH SCHOOL, AL WARQAA


Computer Science Workshop : Grade 12
MU32 ND02 S Mittal P
245, AB Colony
Mumbai
ND48 MU50 B P Jain
13, Block D, A Vihar New Delhi
(i) To display the names of all Consignors from Mumbai.
(b) (i)
SELECT CnorName FROM CONSIGNOR WHERE
City=Mumbai;
( Mark for correct use of SELECT and FROM)
( Mark for correct use of WHERE clause)
(ii) To display the CneelD, CnorName, CnorAddress, CneeName,
CneeAddress for every Consignee.
(ii)
SELECT B.CneeID, A.CnorName, A.CnorAddress,
B.CneeName , B.CneeAddress
FROM Consignor A, Consignee B
WHERE A.CnorID=B.CnorID;
OR
SELECT Consigner.CneeID, CnorName, CnorAddress,
CneeName, neeAddress
FROM Consignor, Consignee
WHERE Consignor.CnorID= Consignee.CnorID;
( Mark for correct use of SELECT and FROM)
( Mark for correct use of WHERE clause)
(iii) To display consignee details in ascending order of CneeName.
(iii)
SELECT * FROM CONSIGNEE ORDER BY CneeName;
( Mark for correct use of SELECT and FROM)
( Mark for correct use of ORDER BY clause)
(iv) To display number of consignors from each city,
(iv)
SELECT City,Count(CnorID) FROM CONSIGNOR Group
By City;
OR
SELECT City,Count(*) FROM CONSIGNOR Group By
City;
( Mark for correct use of SELECT and FROM)
( Mark for correct use of GROUP BY clause)
(v) SELECT DISTINCT City FROM CONSIGNEE;
(v)
DISTINCT City
Mumbai
New Delhi
Kolkata
( Mark for correct output)
Databases and SQL
27

OUR OWN HIGH SCHOOL, AL WARQAA


Computer Science Workshop : Grade 12
OR
( Mark for mentioning Error as CITY not present in the table
CONSIGNEE)
(vi) SELECT A.CnorName, B.CneeName
FROM Consignor A, Consignee B
WHERE A.CnorID = B.CnorlD AND B.CneeCity = Mumbai;
(vi)
A.CnorName B.CneeName
R Singhal
Rahul Kishore
Amit Kumar S Mittal
( Mark for correct output)
OR
( Mark for any 2 correct output out of (v),(vii)and (viii) even if
part (vi) not attempted)
(vii) SELECT CneeName, CneeAddress
FROM Consignee
WHERE CneeCity NOT IN (Mumbai, Kolkata);
(vii)
CneeName CneeAddress
P Dhingra
16/J,Moore Enclave
B P Jain
13,Block D,A Vihar
( Mark for correct output)
(viii) SELECT CneelD, CneeName
FROM Consignee
WHERE CnorID=MU15' OR CnorID=ND01';
(viii)
CneeID
CneeName
MU05 Rahul Kishore
KO19 A P Roy
( Mark for correct output)
Note: Column Headings for all Outputs may be ignored
YEAR 2008 (OUTSIDE DELHI)
5 a) Differentiate between Candidate Key and Alternate Key in context of
RDBMS.
2
Ans: Candidate Key: It is the one that is capable of becoming primary key i.e., a
column or set of columns that identifies a row uniquely in the relation.
Alternate Key: A candidate key that is not selected as a primary key is called
an Alternate Key.
(1 Mark each for correct definition/explanation of Candidate Key and
Alternate Key)
OR
Databases and SQL
28

OUR OWN HIGH SCHOOL, AL WARQAA


Computer Science Workshop : Grade 12
(Full 2 Marks for illustrating the concept of Candidate and Alternate key with
appropriate example)
.
(b) Consider the following tables Item and Customer. Write SQL commands
for the statements (i) to (iv) and give outputs for SQL queries (v) to (viii) 6
TABLE : ITEM

Databases and SQL


29

OUR OWN HIGH SCHOOL, AL WARQAA


Computer Science Workshop : Grade 12

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

OUR OWN HIGH SCHOOL, AL WARQAA


Computer Science Workshop : Grade 12
FROM CUSTOMER C, ITEM I WHERE C.I_Id=I.I_ID;
OR
SELECT CUSTOMER.CustomerName, CUSTOMER.City,
ITEM. ItemName, ITEM. Price
FROM CUSTOMER, ITEM WHERE CUSTOMER.I_Id=ITEM.I_ID;
( Mark for correct use of SELECT and FROM)
( Mark for correct use of WHERE clause)
(iv) To increase the Price of all Items by 1000 in the table Item
Ans:
UPDATE ITEM SET PRICE=PRICE+1000;
( Mark for cbrrect use of UPDATE)
( Mark for correct use of SET)
(v) SELECT DISTINCT City FROM Customer;
Ans:
DISTINCT City
Delhi
Mumbai
Bangalore
( Mark for correct output - ignore the order of City in the output &
Column Header)
(vi) SELECT ItemName, MAX(Price), Count(*)
FROM Item GROUP BY ItemName;
Ans:
ItemName
Max (Price) Count ( * )
Personal Computer 37000
3
Laptop
57000
2
( Mark for correct output - ignore the order of rows in the output & Column
Headers)
(vii) SELECT CustomerName, Manufacturer FROM Item, Customer
WHERE Item.Item_Id=Customer.Item.I_Id
Ans:
CustomerName Manufacturer
N Roy
PQR
H Singh
XYZ
R Pandey
COMP
C Sharma
PQR
K Agarwal
ABC
( Mark for correct output - ignore the order of rows in the output & Column
Headers)
OR
( Mark for mentioning syntax error or error as the column Item_ld is not
present)
Databases and SQL
31

OUR OWN HIGH SCHOOL, AL WARQAA


Computer Science Workshop : Grade 12
(viii) SELECT ItemName, Price * 100
FROM Item WHERE Manufacturer =ABC;
Ans:
ItemName
Price*100
Personal Computer 3500000
Laptop
5500000
( Mark for correct output - ignore the order of rows in the output &
Column Headers)

YEAR 2008 (DELHI)


a) Differentiate between Candidate Key and Primary Key in context of RDBMS
Ans:
Candidate Key:
All such attributes/columns, which can uniquely identify each
row/record in a table
Primary Key:
An attribute/column among the Candidate Keys which is used
to uniquely identify each row/record in a table
(2 Marks for any valid difference/relation between Candidate Key and Primary
Key)
OR
(1 Mark for correct explanation of Candidate Key)
(1 Mark for correct explanation of Primary Key)
(b) Consider the following tables Product and Client. Write SQL commands for the
statement (i) to (iv) and give outputs for SQL queries (v) to (viii) 6
TABLE: PRODUCT

Databases and SQL


32

OUR OWN HIGH SCHOOL, AL WARQAA


Computer Science Workshop : Grade 12

TABLE: CLIENT

(i) To display the details of those Clients whose City is Delhi


Ans :
SELECT * FROM Client WHERE City = Delhi;
( Mark for correct SELECT)
( Mark for correct WHERE clause)
(ii) To dis pl ay the details of Products whose Price is in the range of 50 to
100 (Both values included)
Ans:
SELECT * FROM Product
WHERE Price >=50 AND Price <=100;
OR
SELECT * FROM Product
WHERE Price BETWEEN 50 AND 100;
( Mark for correct SELECT)

( Mark for correct WHERE clause)


(iii) To display the ClientName, City from Table Client, and ProductName
and Price from table Product, with their corresponding Matching P_ID
Ans:
SELECT ClientName, City, ProductName, Price, Client.P_ID
FROM Client, Product
WHERE Client.P_ID = Product. P_ID;
( Mark for correct SELECT)
Databases and SQL
33

OUR OWN HIGH SCHOOL, AL WARQAA


Computer Science Workshop : Grade 12
( Mark for correct WHERE clause)
(iv) To increase the Price of all Products by 10
Ans:
UPDATE Product SET Price = Price +10;
( Mark for correct SELECT)
( Mark for correct WHERE clause)
(v) SELECT DISTINCT Address FROM Client
Ans:
DISTINCT City
Bangalore
Delhi
Mumbai
( Mark for correct output)
OR
( Mark for mentioning Address is not a Column in the Table Client OR
mentioning ERROR)
(vi) SELECT Manufacturer, MAX(Price), Min(Price), Count(*)
FROM Product GROUP BY Manufacturer;
Ans:
Manufacturer
MAX(Price) MIN(Price) Count(*)
ABC
55
45
2
LAK
40
40
1
XYZ
120
95
2
( Mark for correct output)
(vii) SELECT ClientName, ManufacturerName FROM Product, Client
WHERE Client.Prod_Id = Product.P_Id;
Ans:
ClientName Manufacturer
Cosmetic Shop
ABC
Total Health ABC
Live life
XYZ
Pretty Woman XYZ
Dreams
LAK
( Mark for correct output)
OR
( Mark for mentioning ManufactureName and Prod_ld are not valid Column
in the respective Tables)
(viii) SELECT ProductName, Price * 4 from Product;
Ans:
Product Name
Price * 4
Talcom Powder
160
Face Wash
180
Bath Soap
220
Shampoo
480
Face Wash
380
( Mark for correct output)
NOTE:
For Parts (v) to (viii), Ignore the Column Header and order of output rows

Databases and SQL


34

OUR OWN HIGH SCHOOL, AL WARQAA


Computer Science Workshop : Grade 12
(a)

CBSE SAMPLE PAPER 1 (2009)


What do you understand by Degree and Cardinality of a table?

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

OUR OWN HIGH SCHOOL, AL WARQAA


Computer Science Workshop : Grade 12
( mark for correct SELECTion of columns)
( mark for correct use of ORDER BY)
(iv) To display the content of the ACTIVITY table whose ScheduleDate earlier than 01/01/2004 in
ascending order of ParticipantsNum.
Answer:
SELECT * FROM ACTIVITY WHERE ScheduleDate<01-Jan-2004 ORDER BY
ParticipantsNum;
( mark for correct SELECTion of columns)
( mark for correct use of ORDER BY)
(i) SELECT COUNT(DISTINCT ParticipantsNum) FROM ACTIVITY;
Answer:
3
( mark for correct output)
(vi)SELECT MAX(ScheduleDate),MIN(ScheduleDate) FROM ACTIVITY;
Answer:
19-Mar-2004
12-Dec-2003
( mark for correct output)
(vii)
Answer:
54000

SELECT SUM(PrizeMoney) FROM ACTIVITY;

( mark for correct output)


(viii) SELECT DISTINCT ParticipantsNum FROM ACTIVITY;
Answer:
16
10
12
( mark for correct output)

CBSE SAMPLE PAPER 2 (2009)


(a)

What do you understand by Primary Key & Candidate Keys?


2
Answer:
Databases and SQL
36

OUR OWN HIGH SCHOOL, AL WARQAA


Computer Science Workshop : Grade 12
An attribute or set attributes which are used to identify a tuple uniquely is known as Primary Key. If a
table has more than one such attributes which identify a tuple uniquely than all such attributes are
known as Candidate Keys.
(b) Consider the following tables GAMES and PLAYER. Write SQL commands for the statements (i)
to (iv) and give outputs for SQL queries (v) to (viii)
6
Table: GAMES
GCode GameName
101
Carom Board
102
Badminton
103
Table Tennis
105
Chess
108
Lawn Tennis

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

To display the name of all Games with their Gcodes

SELECT GameName,Gcode FROM GAMES;


(1 mark for correct SELECTion of columns)
(ii) To display details of those games which are having PrizeMoney more than 7000.
Answer:
SELECT * FROM GAMES WHERE PrizeMoney>7000
( mark for correct SELECTion of columns)
( mark for correct use of WHERE)
(iii)
To display the content of the GAMES table in ascending order of ScheduleDate.
Answer:
SELECT * FROM GAMES ORDER BY ScheduleDate;
( mark for correct SELECTion of columns)
( mark for correct use of ORDER BY)
(i) To display sum of PrizeMoney for each of the Number of participation groupings (as shown in
column Number 2 or 4)
Answer:
SELECT SUM(PrizeMoney),Number FROM GAMES GROUP BY Number;
( mark for correct SELECTion of columns)
( mark for correct use of GROUP BY)
(ii) SELECT COUNT(DISTINCT Number) FROM GAMES;
Answer:
2
( mark for correct output)
Databases and SQL
37

OUR OWN HIGH SCHOOL, AL WARQAA


Computer Science Workshop : Grade 12
(vi)SELECT MAX(ScheduleDate),MIN(ScheduleDate) FROM GAMES;
Answer:
19-Mar-2004 12-Dec-2003
( mark for correct output)
(vii)
Answer:

SELECT SUM(PrizeMoney) FROM GAMES;

59000
( mark for correct output)
(viii) SELECT DISTINCT Gcode FROM PLAYER;
Answer:
101
103
108
( mark for correct output)

Year 2009 (Delhi)


5. (a) What are candidate keys in a table? Give a suitable example of candidate
keys in a table. 2
Ans A table may have more than one such attribute/group of attribute that identifies
a tuple uniquely, all such attribute(s) are known as Candidate Keys.
Table:Item
Ino
I01
I02
I04
I09
I05
I03

Item
Pen
Pencil
CD
Floppy
Eraser
Duster

Qty
560
780
450
700
300
200

(1 Mark for writing correct definition of Candidate Key)


(1 Mark for giving suitable example)
OR
(2 Marks for illustrating Candidate Key with/without showing it as a part of
a Table)
(b) Consider the following tables GARMENT and FABRIC. Write SQL
commands for the statements (i) to (iv) and give outputs for SQL queries
(v) to (viii) 6
Table: GARMENT
GCODE DESCRIPTION
PRICE FCODE READYDATE
10023
PENCIL SKIRT
1150
F03
19-DEC-08
10001
FORMAL SHIRT
1250
F01
12-JAN-08
10012
INFORMAL SHIRT 1550
F02
06-JUN-08
Databases and SQL
38

10024
10090
10019
10009
10007
10020
10089

OUR OWN HIGH SCHOOL, AL WARQAA


Computer Science Workshop : Grade 12
BABY TOP
750
F03
07-APR-07
TULIP SKIRT
850
F02
31-MAR-07
EVENING GOWN
850
F03
06-JUN-08
INFORMAL PANT
1500
F02
20-OCT-08
FORMAL PANT
1350
F01
09-MAR-08
FROCK
850
F04
09-SEPT-07
SLACKS
750
F02
20-OCT-08
Table : FABRIC

FCODE
F04
F02
F03
F01

TYPE
POLYSTER
COTTON
SILK
TERELENE

(i) To display GCODE and DESCRIPTION of each GARMENT in descending


order of GCODE
Ans SELECT GCODE, DESCRIPTION FROM GARMENT
ORDER BY GCODE DESC;
(1 Mark for correct query)
( Mark for partially correct answer)
(ii) To display the details of all the GARMENTs, which have READYDA TE in
between 08-DEC-07 and 16-JUN-08(inclusive of both the dates).
Ans SELECT * FROM GARMENT WHERE READYDATE BETWEEN 08DEC-07 AND , 16-JUN-08 ;
OR
SELECT * FROM DRESS WHERE LAUNCHDATE >= 08-DEC-07
AND LAUNCHDATE<=16-JUN-08;
(1 Mark for correct query)
( Mark for partially correct answer)
(iii) To display the average PRICE of all the GARMENTs, which are made up of
FABRIC with FCODE as F03.
Ans SELECT AVG (PRICE) FROM GARMENT WHERE FCODE = F03;
(1 Mark for correct query)
( Mark for partially correct answer)
(iv) To display FABRIC wise highest and lowest price of GARMENTs from
GARMENT table. (Display FCODE of each GARMENT along with highest
and lowest price)
Ans SELECT FCODE, MAX (PRICE), MIN(PRICE) FROM GARMENT
GROUP BY FCODE;
(1 Mark for correct query)
( Mark for partially correct answer)
(v) SELECT SUM (PRICE) FROM GARMENT WHERE FCODE = F01 ;
Ans SUM (PRICE)
26:10
( Mark for correct output)
(vi) SELECT DESCRIPTION, TYPE FROM GARMENT, FABRIC WHERE
GARMENT.FCODE = FABRIC.FCODE AND GARMENT. PRICE > =
Databases and SQL
39

OUR OWN HIGH SCHOOL, AL WARQAA


Computer Science Workshop : Grade 12
1260 ;
Ans DESCRIPTION TYPE
INFORMAL SHIRT COTTON
INFORMAL PANT COTTON
FORMAL PANT TERELENE
( Mark for correct output)
(vii) SELECT MAX (FCODE) FROM FABRIC;
Ans MAX (FCODE)
F04
( Mark for correct output)
(viii) SELECT COUNT (DISTINCT PRICE) FROM GARMENT ;
Ans COUNT(DISTINCT PRICE)
7
( Mark for correct output)
Year 2009 (Outside Delhi)
5 (a) What is the purpose of a key in a table? Give an example of a key in a Table.

(2)

Ans An attribute/group of attributes in a table that identifies each tuple uniquely is


known as a Key.
OR
Any correct definition of Key / Primary Key / Candidate Key / Alternate Key
Table:Item
Ino
I01
I02
I04
I09
I05
I03

Item
Pen
Pencil
CD
Floppy
Eraser
Duster

Qty
560
780
450
700
300
200

(1 Mark for writing correct definition/purpose of any valid Key)


(1 Mark for giving suitable example)
OR
(2 Marks for illustrating the purpose of Key with/without showing it as a part
of a Table)
(b) Consider the following tables DRESS and MATERIAL. Write SQL commands for the statements (i) to (iv)
and give outputs for SQL queries (v) to (viii).
6
DCODE DESCRIPTION
10001
FORMAL SHIRT
10020
FROCK
10012
INFORMAL SHIRT
10019
EVENING GOWN
10090
TULIP SKIRT
10023
PENCIL SKIRT
10089
SLACKS
10007
FORMAL PANT
Databases and SQL

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

OUR OWN HIGH SCHOOL, AL WARQAA


Computer Science Workshop : Grade 12
INFORMAL PANT
1400
M002
20-OCT-08
BABY TOP
650
M003
07-APR-07

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

OUR OWN HIGH SCHOOL, AL WARQAA


Computer Science Workshop : Grade 12
(ii) To display the details of al the dresses which have LAUNCHDATE in between 05-DEC-07 and 20-JUN-08
(inclusive of both the dates).
SQL> SELECT * FROM DRESS WHERE LAUNCHDATE BETWEEN '05-DEC-07' AND '20-JUN-08';
OR
SELECT * FROM DRESS WHERE LAUNCHDATE >= 05-DEC-07
AND LAUNCHDATE<= 20-JUN-08
(1 Mark for correct query)
( Mark for partially correct answer)
DCODE
DESCRIPTION
-----------------------10001 FORMAL SHIRT
10012 INFORMAL SHIRT
10019 EVENING GOWN
10007 FORMAL PANT

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

SQL> SELECT SUM(PRICE) FROM DRESS WHERE MCODE='M001';


SUM(PRICE)
---------------2700
Databases and SQL
42

OUR OWN HIGH SCHOOL, AL WARQAA


Computer Science Workshop : Grade 12
( Mark for correct output)
SQL> SELECT DESCRIPTION, TYPE FROM DRESS, MATERIAL WHERE
DRESS.MCODE=MATERIAL.MCODE AND DRESS.PRICE>=1250;
DESCRIPTION
------------------FORMAL SHIRT
FORMAL PANT
INFORMAL SHIRT
INFORMAL PANT
PENCIL SKIRT
( Mark for correct output)

TYPE
--------TERELENE
TERELENE
COTTON
COTTON
SILK

SQL> SELECT MAX(MCODE) FROM MATERIAL;


MAX(MCODE)
------------------M004
( Mark for correct output)
SQL> SELECT COUNT(DISTINCT PRICE) FROM DRESS;
COUNT(DISTINCTPRICE)
---------------------------------6
( Mark for correct output)
SQL> SELECT DISTINCT PRICE FROM DRESS;
PRICE
---------650
750
850
1250
1400
1450
6 rows selected.
( Mark for correct output)

Databases and SQL


43

OUR OWN HIGH SCHOOL, AL WARQAA


Computer Science Workshop : Grade 12
(vi) SELECT DESCRIPTION, TYPE FROM DRESS, MATERIAL WHERE
DRESS.DCODE = MATERIAL.MCODE AND DRESS.PRICE>=l250;
Ans DESCRIPTION TYPE
(NO OUTPUT)
( Mark for the above)
OR
( Mark for attempting the question)

Year 2010 (Outside Delhi)


5.(a) What do you understand by Primary Key ? Give a suitable example of Primary Key from a table
containing some meaningful data.
2
Ans An attribute/group of attributes in a table that identifies each tuple uniquely is known as a Primary Key.
Table:Item
Ino
I01
I02
I04
I09
I05
I03

Item
Pen
Pencil
CD
Floppy
Eraser
Duster

Qty
560
780
450
700
300
200

In above table Ino is the Primary Key.


(1 Mark for writing correct definition/purpose of Primary Key)
(1 Mark for giving suitable example)
OR
(2 Marks for illustrating the purpose of Key with/without showing it as a part
of a Table)
(c) Consider the following tables STOCK and DEALERS and answer (bi) and (b2) parts of this question

Table: STOCK
Databases and SQL
44

OUR OWN HIGH SCHOOL, AL WARQAA


Computer Science Workshop : Grade 12
ItemNo
5005
5003
5002
5006
5001
5004
5009

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

(bl) Write,SQL commands for the following statements: 4


(i) To display details of all Items in the Stock table in ascending order of StockDate.
Ans:
SQL> SELECT * FROM Stock ORDER BY StockDate ASC;
ITEMNO ITEM
---------- -------------------5006 Gel Pen Classic
5009 Sharpener Classic
5001 Eraser Small
5004 Eraser Big
5003 Ball Pen 0.25
5002 Gel Pen Premium
5005 Ball Pen 0.5

DCODE
---------101
103
102
102
102
101
102

QTY UNITPRICE STOCKDATE


---------- -----------------200
22
01-JAN-09
160
8
23-JAN-09
210
5
19-MAR-09
60
10
12-DEC-09
150
20
01-JAN-10
125
14
14-FEB-10
100
16
31-MAR-10

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

OUR OWN HIGH SCHOOL, AL WARQAA


Computer Science Workshop : Grade 12
ITEMNO ITEM
DCODE QTY UNITPRICE STOCKDATE
---------- -------------------- ---------- ---------- -----------------5005 Ball Pen 0.5
102
100
16
31-MAR-10
5003 Ball Pen 0.25
102
150
20
01-JAN-10
5002 Gel Pen Premium
101
125
14
14-FEB-10
5006 Gel Pen Classic
101
200
22
01-JAN-09
5001 Eraser Small
102
210
5
19-MAR-09
5004 Eraser Big
102
60
10
12-DEC-09
5009 Sharpener Classic 103
160
8
23-JAN-09
7 rows selected.
(iv) To display Maximum UnitPrice of items for each dealer individually as per Dcode from the table Stock.
Ans.:
SQL> SELECT Dcode, MAX(UnitPrice) FROM Stock GROUP BY Dcode;
DCODE MAX(UNITPRICE)
---------- -------------101
22
102
20
103
8
(b2) Give the output of the following SQL queries
(i) SELECT COUNT (DISTINCT Dcode) FROM Stock;

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

OUR OWN HIGH SCHOOL, AL WARQAA


Computer Science Workshop : Grade 12
01-JAN-09

Q: Write a query to display the total unit price, average unit price, highest
unit price, lowest unit price, number of unit prices.

***************

Databases and SQL


47

Das könnte Ihnen auch gefallen