RDBMS and SQL Queries XII Computer Science Important Question Cbse
RDBMS and SQL Queries XII Computer Science Important Question Cbse
Question 1:
Observe the following PARTICIPANTS and EVENTS table cerefully 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.
Answer:
Cartesian Product
Degree — 4
Cardinality = 6
Question 2:
Define degree and cardinality. Also, Based upon given table write degree and
cardinality.
Answer:
Degree is the number of attributes or columns present in a table.
Cardinality is the number of tuples or rows present in a table.
Patients Degree = 4
Cardinality = 5
Question 3:
Observe the following table and answer the parts (i) and (ii):
Answer:
1. We cannot use Qty as primary key because there is a duplication of values and
primary key value cannot be duplicate.
2. Degree =4
Cardinality = 5
Question 4:
Explain the concept of union between two tables, with the help of appropriate example.
Answer:
The union operation denoted by ‗U‘ combines two or more relations. The resultant of
union operation contain tuples that are in either of the table or in both tables.
Question 5:
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 table?
Also, find the degree and cardinality of the table.
Answer:
Cartesian Product
Degree = 4
Cardinality = 6
Question 6:
Observe the following MEMBER and ACTIVITY tables carefully and write the name of
the RDBMS operation, which will be used to produce the output as shown in REPORT?
Also, find the Degree and Cardinality of the REPORT.
Answer:
Join operation or MEMBER U ACTIVITY
Degree of Report = No of columns
(No of Attributes) = 3
Candinality Report = No of Rows
(No of tuples) = 6
Question 7:
Observe the table ‗Club‘ given below:
Answer:
1. Cardinality = 4 Degree = 5
2. Cardinality = 7
3. Degree = 6
Question 8:
What do you understand by Union & Cartesian product in the relational algebra?
Answer:
Union of R ans S :The Union of two relations is a relation that includes all the tuples
that are either in R or in S or in both R and S. Duplicate tuples are eliminated.
The Union is an operator which works on two how sets. It combines the tuples of one
relation with all the tuples of the other relation such that there is no duplication.
Cartesian Product: The cartesian product is an operator which works on two sets. It
combines the tuples of one relation with all the tuples of the other relation.
Example: Cartesian Product
Question 9:
Differentiate between the Alternate key of a table with the help of an example.
Answer:
Primary Key: A primary key is a value that can be used to identify a unique row in a
table .
Alternate Key: An alternate key is any candidate key which is not selected to be the
primary key
Example:
So, (Bank Account Number, Aadhaar Number) are candidate keys for the table.
Aadhaar Number — Primary key
Bank Account Number — Alternate key
Question 10:
Explain the concept of candidate key with the help of an appropriate example.
Answer:
Candidate key is a column or set of columns that can help in identifying records
uniquely.
Example, consider a Table STUDENT.
Question 11:
What do you understand by degree & cardinality of a Table ?
Answer:
Degree refers to the number of columns in a table.
Cardinality refers to the number of rows.
Question 12:
Observe the following table and answer the part (i) and (ii)
accordingly.
1. In the above table, can we take Mno as Primary key ? (Answer as [Yes/No]
only.) Justify your answer with a valid reason.
2. What is the degree and the cardinality of the above table?
Answer:
1. No
2. Degree = 4
Cardinality = 5
[Hint: Because Pencil and Eraser are having the same Mno = 2. Primary key
needs to be unique]
Question 13:
Give a suitable example of a table with sample data and illustrate Primary and
Candidate keys in it.
Answer:
A table may have more than one such attribute or a group of attribute that identifies a
row/ tuple uniquely, all such attribute(s) are known as Candidate keys. Out of the
Candidate keys, one is selected as Primary key.
Question 14:
What do you understand by selection and projection operations in the relational
algebra?
Answer:
Projection (n): In relational algebra, projection is a unary operation. The result of such
projection is defined as the set obtained when the components of the tuple R are
restricted to the set {a1…,an} – it discards (or exculdes) the other attributes.
Selection ( ): In relational algebra, a selection is a unary operation written as (R)
or (R) where:
Question 15:
What do you understand by Primary key and Candidate keys.
Answer:
An attribute or set of attributes which are used to identify a tuple uniquely is known as
primary key. If a tuple has more than one such attribute which identify a tuple uniquely,
than all such attributes are known as candidate keys.
Question 16:
What is relation? Define the relational data model.
Answer:
A relation is a table having atomic values, unique row, and unordered rows and
columns. The relational model represent data and relationship among data by a
collection of tables known as relation, each of which has a number of columns with
unique names.
Question 17:
Define domain with respect to database. Give an example.
Answer:
A domain is a pool of values from which the actual values appearing in a given column
are drawn.
For example: The values appearing in the Supp# column of both the suppliers table and
the Shipment table are drawn from the same domain.
Question 18:
Expand the following:
1. SQL
2. DBMS
Answer:
Question 19:
What do you understand by candidate keys in a table? Give a suitable example of
candidate keys from a table containing some meaningful data.
Answer:
Candidate key: A candidate key is one that can identify each row of a table uniquely.
Generally, a candidate key becomes the primary key of the table. If the table has more
than one candidate key, one of them will become the primary key, and the rest are
called alternate keys.
Example:
Question 20:
What are all the domain names possible in gender ?
Answer:
Male and Female
Question 21:
A table ‗customer‘ has 10 columns but no row. Later, 10 new rows are inserted and 3
rows are deleted in the table. What is the degree and cardinality of the table customer.
Answer:
Degree = 10 [no. of cols]
Cardinality = 10-3 = 7 [no. of rows]
Question 22:
A table ‗student‘ has 3 columns and 10 rows and another table ‗student 2‘ has the same
columns as student but 15 rows. 5 rows are common in both the tables. If we take
union, what is the degree and cardinality of the resultant table ?
Answer:
Degree = 3
Cardinality = 30 (20 + 15 – 5)
Question 23:
A table ‗student‘ has 4 columns and 10 rows and ‗student 2‘ has 5 columns and 5 rows.
If we take cartesian product of these two tables, what is the degree and cardinality of
the resultant table ?
Answer:
Degree = 4 x 5 = 20 [no. of columns]
Cardinality = 10 x 5 = 50 [no. of rows]
Question 24:
In the following 2 tables, find the union value of Student 1 and Student 2.
Answer:
Question 1:
Write queries for (i) to (iv) and find ouputs for SQL queries (v) to (viii), which are based
on the tables.
Table :
VEHICLE
Note:
1. Select Designation Count (*) From Admin Group By Designation Having Count (*)
<2;
2. SELECT max (EXPERIENCE) FROM SCHOOL;
3. SELECT TEACHER FROM SCHOOL WHERE EXPERIENCE >12 ORDER BY
TEACHER;
4. SELECT COUNT (*), GENDER FROM ADMIN GROUP BY GENDER;
Answer:
Question 3:
Write SQL qureries for (i) to (iv) and find outputs for SQL queries (v) to (viii), which are
based on the tables TRANSPORT and TRIE
Note:
NO is Driver Number
KM is Kilometer travelled
NOP is number of travellers travelled in vehicle
TDATE is Trip Date
1. To display NO, NAME, TDATE from the table TRIP in descending order of NO.
2. To display the NAME of the drivers from the table TRIP who are traveling by
transport vehicle with code 101 or 103.
3. To display the NO and NAME of those drivers from the table TRIP who travelled
between ‗2015-02-10‘ and ‗2015-04-01‘.
4. To display all the details from table TRIP in which the distance travelled is more
than 100 KM in ascending order of NOP
5. SELECT COUNT (*), TCODE From TRIP
GROUP BY TCODE HAVNING COUnT (*) > 1;
6. SELECT DISTINCT TCODE from TRIP;
7. SELECT A.TCODE, NAME, TTYPE
FROM TRIP A, TRANSPORT B
WHERE A. TCODE = B. TCODE AND KM < 90;
8. SELECT NAME, KM *PERKM
FROM TRIP A, TRANSPORT B
WHERE A. TCODE = B. TCODE AND A. TCODE = 105′;
Answer:
Question 4:
Write SQL query to add a column total price with datatype numeric and size 10, 2 in a
table product.
Answer:
ALTER TABLE PRODUCT ADD TOTAL PRICE NUMBER (10,2).
Question 5:
Sonal needs to display name of teachers, who have ―0‖ as the third character in their
name. She wrote the following query.
SELECT NAME FROM TEACHER WHERE NAME = ―$$0?‖;
But the query is‘nt producing the result. Identify the problem.
Answer:
The wildcards are incorrect. The corrected query is SELECT NAME FROM TEACHER
WHERE NAME LIKE ‗_ _0%‘.
Question 6:
Deepika wants to remove all rows from the table BANK. But he needs to maintain the
structure of the table. Which command is used to implement the same?
Answer:
DELETE FROM BANK.
Question 7:
While creating table ‗customer‘, Rahul forgot to add column ‗price‘. Which command is
used to add new column in the table. Write the command to implement the same.
Answer:
ALTER TABLE CUSTOMER ADD PRICE NUMBER (10, 2).
Question 8:
What is the use of wildcard
Answer:
The wildcard operators are used with the LIKE operator to search a value similar to a
specific pattern in a column. There are 2 wildcard operators.
% – represents 0,1 or many characters – – represents a single number or character
Question 9:
Differentiate between DELETE and DROP table commands ?
Answer:
DELETE command is used to remove infor¬mation from a particular row or rows. If
used without condition, it will delete all row information but not the structure of the table.
It is a DML command.
DROP table command is used to remove the entire structure of the table and
information. It is a DDL command
Question 1:
Write SQL commands for the queries (i) to (iv) and output for (v) & (viii) based on a
table COMPANY and CUSTOMER.
1. To display those company name which are having prize less than 30000.
2. To display the name of the companies in reverse alphabetical order.
3. To increase the prize by 1000 for those customer whose name starts with „S?
4. To add one more column totalprice with decimal] 10,2) to the table customer
5. SELECT COUNT(*) , CITY FROM COMPANY GROUP BY CITY;
6. SELECT MIN(PRICE), MAX(PRICE) FROM CUSTOMER WHERE QTY>10;
7. SELECT AVG(QTY) FROM CUSTOMER WHERE NAME LIKE ―%r%;
8. SELECT PRODUCTNAME,CITY, PRICE
FROM COMPANY, CUSTOMER WHERE
COMPANY. CID=CUSTOMER.CID AND
PRODUCTNAME=‖MOBILE‖;
Answer:
5.
6. 50000,70000
7. 11
8.
Question 2:
Consider the following tables SCHOOL and ADMIN and answer this question :
Write SQL statements for the following:
Answer:
Question 3:
Write SQL commands for the queries (i) to (iv) and output for (v) to (viii) based on the
tables Watches‘ and Sale given below.
1. TO DISPLAY ALL THE DETAILS OF THOSE WATCHES WHOSE NAME ENDS
WITH ‗TIME‘
2. TO DISPLAY WATCH‘S NAME AND PRICE OF THOSE WATCHES WHICH
HAVE PRICE RANGE IN BE-TWEEN 5000-15000.
3. TO DISPLAY TOTAL QUANTITY IN STORE OF UNISEX TYPE WATCHES.
4. TO DISPLAY WATCH NAME AND THEIR QUANTITY SOLD IN FIRST
QUARTER;
5. SELECT MAX (PRICE), MIN(QTY_STORE) FROM WATCHES;
6. SELECT QUARTER, SUM(QTY SOLD) FROM SALE GROUP BY QUARTER;
7. SELECT WATCH_NAME, PRICE, TYPE FROM WATCHES W, SALE S WHERE
W. WAT£H1D!=S.WATCHID; (viii) SELECT WATCH_NAME, QTYSTORE, SUM
(QTY_SOLD), QTY_STORESUM (QTYSOLD) ―STOCK‖ FROM WATCHES W,
SALE S WHERE W. WATCHID = S.WATCHID GROUP BY S.WATCHID;
Answer:
Question 4:
Answer the questions (a) and (b) on the basis of the following tables SHOP and
ACCESSORIES.
1. To display Name and Price of all the Accessories in ascending order of their Price.
2. To display Id and SName of all Shop located in Nehru Place.
3. To display Minimum and Maximum Price of each Name of Accessories.
4. To display Name, Price of all Accessories and their respective SName where they
are available.
Answer:
(a)
1. SELECT Name, Price FROM ACCESSORIES ORDER BY Price Asc;
2. SELECT ID SName FROM SHOP WHERE Area=‖Nehru Place‖;
3. SELECT Name, max (Price); min(Price) FROM ACCESSORIES, Group By Name;
4. SELECT Name,price, Sname FROM
ACCESSORIES, SHOP WHERE SHOE
ID=ACCESSORIES.ID;
(b)
Question 5:
Write SQL queries for:
1. To display name, fee, gender, joinyear about the applicants, who have joined
before 2010.
2. To display names of applicants, who are playing fee more than 30000.
3. To display names of all applicants in ascending order of their joinyear.
4. To display the year and the total number of applicants joined in each YEAR from
the table APPLICANTS.
5. To display the C_ID (i.e., CourselD) and the number of applicants registered in the
course from the APPLICANTS and table.
6. To display the applicant‘s name with their respective course‘s name from the
tables APPLICANTS and COURSES.
7. Give the output of following SQL statements:
o SELECT Name, Joinyear FROM APPLICANTS
WHERE GENDER=‘F‘ and C_ID=‘A02′;
o SELECT MIN (Joinyear) FROM
APPLICANTS
WHERE Gender=‘m‘;
o SELECT AVG (Fee) FROM APPLICANTS
WHERE C_ID=‘A0T OR C_ID=‘A05′;
o SELECT SUM- (Fee), C_ID FROM C_ ID
GROUP BY C_ID
HAVING COUNT(*)=2;
Answer:
1. SELECT NAME,FEE,GENDER,JOINYEAR
FROM APPLICANTS
WHERE J OINYE AR <2010
2. SELECT NAME FROM APPLICANTS WHERE FEE >30000
3. SELECT NAME FROM APPLICANTS ORDERBY JOINYEAR ASC
4. SELECT YEAR, COUNT]*) FROM
APPLICANTS GROUP BY YEAR;
5. SELECT C_ID, COUNT]*) FROM
APPLICANTS, COURSES GROUP BY ID
WHERE APPLICANTS.C_ID=COURSES. C_ID
6. SELECT NAME,COURSE FROM
APPLICANTS, COURSES
WHERE APPLICANTS. C_ID=COURSES. C_ID
o Avisha 2009
o 2009
o 67
o 55000 A01
Question 6:
Write SQL queries for (a) to (g) and write the output for the SQL queries mentioned
shown in (hi) to (h4) parts on the basis of table ITEMS and TRADERS :
1. To display the details of all the items in ascending order of item names (i.e.,
INAME).
2. To display item name and price of all those items, whose price is in the range of
10000 and 22000 (both values inclusive).
3. To display the number of items, which are traded by each trader. The expected
output of this query should be:
4. To display the price, item name and quantity (i.e., qty) of those items which have
quantity more than 150.
5. To display the names of those traders, who are either from DELHI or from
MUMBAI.
6. To display the names of the companies and the names of the items in descending
order of company names.
7. Obtain the outputs of the following SQL queries based on the data given in tables
ITEMS and TRADERS above.
o SELECT MAX (PRICE), MIN (PRICE) FROM ITEMS;
o SELECT PRICE*QTY
FROM ITEMS WHERE CODE-1004;
o SELECT DISTINCT TCODE FROM ITEMS;
o SELECT INAME, TNAME FROM ITEMS I, TRADERS T WHERE
I.TCODE=T.TCODE AND QTY< 100;
Answer:
Question 7:
Write SQL queries for (a) to (f) and write the outputs for the SQL queries mentioned
shown in (gl) to (g4) parts on the basis of tables PRODUCTS and SUPPLIERS
1. To display the details of all the products in ascending order of product names (i.e.,
PNAME).
2. To display product name and price of all those products, whose price is in the
range of 10000 and 15000 (both values inclusive).
3. To display the number of products, which are supplied by each suplier. i.e., the
expected output should be;
o S01 2
o S02 2
o S03 1
4. To display the price, product name and quantity (i.e., qty) of those products which
have quantity more thhn 100.
5. To display the names of those suppliers, who are either from DELHI or from
CHENNAI.
6. To display the name of the companies and the name of the products in
descending order of company names.
7. Obtain the outputs of the following SQL queries based on the data given in tables
PRODUCTS and SUPPLIERS above.
o SELECT DISTINCT SUPCODE FROM PRODUCTS;
o SELEC MAX (PRICE), MIN (PRICE) FROM PRODUCTS;
o SELECT PRICE*QTY
FROM PRODUCTS WHERE PID = 104; (g4)
o SELECT PNAME, SNAME
FROM PRODUCTS P, SUPPLIERS S WHERE E SUPCODE = S.
SUPCODE
AND QTY>100;
Answer:
Question 8:
Consider the following tables CARDEN and CUSTOMER and answer (b) and (c) parts
of this question:
1. Give a suitable example of a table with sample data and illustrate Primary and
Alternate Keys in it.
2. Write SQL commands for the following statements:
o To display the names of all the silver coloured cars.
o To display names of car, make and capacity of cars in descending order of
their sitting capacity.
o To display the highest charges at which a vehicle can be hired from
CARDEN.
o To display the customer name and the corresponding name of the cars hired
by them.
3. Give the output of the following SQL queries:
o SELECT COUNT(DISTINCT Make) FROM CARDEN;
o SELECT MAX(Charges), MIN (Charges) FROM CARDEN;
o SELECT COUNTS), Make FROM CARDEN;
Answer:
Question 9:
Consider the following tables CABHUB and CUSTOMER and answer (b) and (c) parts
of this question :
1. Give a suitable example of a table with sample data and illustrate Primary and
Candidate Keys in it.
2. Write SQL commands for the following statements:
o To display the names of all the white coloured vehicles.
o To display name of vehicle name and capacity of vehicles in ascending
order of their sitting capacity.
o To display the highest charges at which a vehicle can be hired from
CABHUB.
o To display the customer name and the corresponding name of the vehicle
hired by them.
3. Give the output of the following SQL queries :
o SELECT COUNT(DISTINCT Make) FROM CABHUB;
o SELECT MAX(Charges), MIN(Charges)
o FROM CABHUB;
o SELECT COUNT (*) Make FROM CABHUB;
o SELECT Vehicle FROM CABHUB WHERE Capacity=4;
Answer:
Question 10:
Consider the following tables EMPLOYEE and DEPARTMENT and answer (a) and (b)
parts of this question.
1. Write SQL commands for the following statements:
o To display all DepName along with the DepCde in descending order of
DepCde.
o To display the average age of Employees in DepCde as 103.
o To display the name of DepHead of the Employee named ―Sanjeev P‖
o To display the details of all employees who has joined before 2007 from
EMPLOYEE table.
2. Give the output of the following SQL queries:
o SELECT COUNT (DISTINCT DepCde) FROM EMPLOYEE;
o SELECT MAX(JoinDate), MIN (JointDate) FROM EMPLOYEE;
o SELECT TName, DepHead FROM EMPLOYEE E, DEPARTMENT D
WHERE E.DepCde = D.DepCde;
o SELECT COUNT (*) FROM EMPLOYEE WHERE Salary > 60000 AND Age
> 30;
Answer:
(a)
Answer:
(a)
(b)
Question 12:
Consider the following tables EMPLOYEE and SALGRADE and answer (b) and (c)
parts of this question:
Answer:
Projection(ff): In relational algebra, a projection is a unary operafion. The result of
such projecion is defined as the set obtained when the components Of the tuple R are
restriceted to the set {a1……an}. It discards (or excludes) the other attributes.
Selection( ): In relational algebra, a selection
is a unary operation written as (R) or (R) where:
The selection (R) selects all those tuples in R for which 9 holds between the a and the b
(b)
Question 13:
Consider the following tables GAMES and PLAYER and answer (b) and (c) parts of this
question :
Answer:
(a) An attribute or set of attributes which are used to identify a tuple uniquely is known
as a 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)
1. SELECT GameName, GCode FROM GAMES;
2. SELECT * FROM Games WHERE PrizeMoney >7000;
3. SELECT * FROM Games ORDER BY ScheduleDate;
4. SELECT SUM(Pnzemoney) FROM Games GROUPBY Type;
(c)
1. 2
2. 19-Mar-2004 12-Dec-2003
3. Ravi Sahai Lawn Tennis
4. 101 108 103
Question 14:
Consider the following tables ACTIVITY and COACH and answer (a) and (b) parts of
this question :
1. To display the names of all activities with their Acodes in descending order.
2. To display sum of PrizeMoney for the Activities played in each of the Stadium
separately.
3. To display the coach‘s name and acodes in ascending order of Acode from the
table Coach.
4. To display the content of the Activity table whose schedule date earlier than 01-
01-2004 in ascending order of Participants Num.
(b) Give the output of the following SQL queries:
Answer:
(a)
(b)
1. 3
2. 12-Dec-2003 19-Mar-2004
3. Ravinder Discuss Throw
4. 1001
1008
1003
Question 15:
Consider the following tables RESORT and OWNEDBY and answer (a) and (b) parts of
this question:
(a)Write SQL commands for the following statements:
1. To display the RCODE and PLACE of all ‗5 STAR‘ resorts in the alphabetical
order of the place from table RESORT.
2. To display the maximum and minimum rent for each type of resort from table
RESORT.
3. To display the details of all resorts which are started after 31-DEC-05 from table
RESORT.
4. Display the OWNER of all ‗5 STAR‘ resorts from tables RESORT and OWNEDBY.
Answer:
(a)
(b)
Question 16:
Consider the following tables STORE and SUPPLIERS and answer (a) and (b) parts of
this question:
1. To display details of all the items in the STORE table in ascending order of
LastBuy.
2. To display ItemNo and Item name of those items from STORE table whose Rate
is more than 15 Rupees.
3. To display the details of those items whose supplier code (Scode) is 22 or
Quantity in Store (Qty) is more than 110 from the table Store.
4. To display minimum Rate of items for each supplier individually as per Scode from
the table STORE.
Answer:
(a)
(b)
1. 3
2. 880
3. Item Sname
Gel Pen Classic Premium Stationers
4. 24-Feb-10
Question 17:
Consider the following tables STOCK and DEALERS and answer (a) and (b) parts of
this question:
1. To display the details of all Items in the STOCK table in ascending order of
StockDate.
2. To display ItemNo and Item name of those items from STOCK table whose
UnitPrice is more than Rupees 10.
3. 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.
4. To display maximum UnitPrice of items for each dealer individually as per Dcode
from the table STOCK.
Answer:
(a)
1. SELECT*FROM STOCK ORDER BY StockDate;
2. SELECT Item No, Item FROM STOCK WHERE UnitPrice >10;
3. SELECT *FROM DEALERS, STOCK
WHERE (DEALERS.Dcode=‖102″OR STOCK.Qty >100 and DEALERS.
DCODE = STOCK.DCODE);
4. SELECT MAX (Unitprice) FROM DEALERS, STOCK ORDER BY STOCK. Dcode
WHERE DEALERS.Dcode = STOCK.Dcode;
(b)
1. 3
2. 4400
3. Item Dname
Eraser Big Clear Deals
4. 01-Jan-09
Narender Kumar
PGT CS
K V Sector-8, R K Puram New Delhi