0% found this document useful (0 votes)
236 views16 pages

1 MCQ-SQL

Download as pdf or txt
0% found this document useful (0 votes)
236 views16 pages

1 MCQ-SQL

Download as pdf or txt
Download as pdf or txt
You are on page 1/ 16

78 CBSE Term II Computer Science XII

Chapter
Practice
PART 1 Ans.(d) ORDER BY keyword sorts the records in ascending
order by default.

Objective Questions 6. The clause used to check NULL values is


(a) IS NULL
(b) IS NOT NULL
l
Multiple Choice Questions (c) Both (a) and (b)
1. Which of the following is/are advantage(s) of SQL? (d) None of the above
(a) High speed (b) Client/server language Ans.(a) The IS NULL clause is used to check NULL values in
(c) Easy to learn (d) All of these a field.
Ans.(d) High speed, client/server language, easy to learn and 7. The .............. operator is used for pattern matching.
understand are advantages of SQL. It is portable and (a) BETWEEN (b) LIKE
used for relational database. (c) IN (d) LOOKSLIKE
2. Which of the following command is used to remove Ans.(b) The LIKE operator is used to match patterns in a
the table definition and all data? field.
(a) CREATE (b) SELECT 8. To delete all the records from a table “Product” the
(c) DROP (d) None of these command will be
Ans.(c) DROP command is used to remove the table (a) DEL FROM Product;
definition and all data. (b) DELETE FROM Product;
3. Which of the following is a correct syntax to add a (c) REMOVE ALL FROM Product;
column in SQL command? (d) DELETE ALL;
(a) ALTER TABLE table_name ADD column_name Ans.(b) To delete all the records from a table ‘‘Product’’ the
data_type; command will be
(b) ALTER TABLE ADD column_name data_type; DELETE FROM Product;
(c) ALTER table_name ADD column_name
data_type;
9. The .............. character displays all the columns of a
table in a SELECT query.
(d) None of the above
(a) # (b) @ (c) * (d) /
Ans.(a) Syntax to add a column in SQL command is
Ans.(c) The * character displays all the columns in a SELECT
ALTER TABLE table_name ADD column_name query.
data_type;
10. The ............ command removes a table completely.
4. Which keyword can be used to return only (a) DELETE (b) REMOVE
different values in a particular column or a whole
(c) DROP (d) UPDATE
table?
Ans.(c) The DROP command removes a table completely
(a) WHERE (b) DISTINCT
along with its data.
(c) ALL (d) BETWEEN
Ans.(b) DISTINCT keyword can be used to return only 11. The “SET” clause is used along with ..............
different values in a particular column or a whole table. command.
(a) DELETE (b) DESCRIBE
5. The ……… keyword sorts the records in ascending (c) CREATE (d) UPDATE
order by default.
Ans.(d) The UPDATE command updates data of a table . It
(a) LIKE (b) UPDATE uses the “SET” clause to specify the field to be updated.
(c) ORDER (d) ORDER BY
CBSE Term II Computer Science XII 79

12. What is true about the following SQL statement? Ans.(d) NULL values are excluded from the result returned
by all the aggregate functions.
mysql> SELECT*FROM Student; (NCERT)
(a) Displays contents of table ‘Student’. 19. The AVG() function in MySQL is an example of
(b) Displays column names and contents of table (a) Math function (b) Text function
‘Student’. (c) Date function (d) Aggregate function
(c) Results in error as improper case has been used. Ans.(d) The AVG() function returns the average value from a
(d) Displays only the column names of table ‘Student’. column or multiple-rows.
Ans.(b) The command displays entire contents of the table So, the AVG ( ) function in MySQL is an example of
along with column names. aggregate function.
13. Which operator is used to compare a value to a 20. Which of the following function count all the values
specified list of values? except NULL?
(a) ANY (b) BETWEEN (a) COUNT(*)
(c) ALL (d) IN (b) COUNT(column_name)
Ans.(d) The IN operator easily tests the expression, if it (c) COUNT(NOT NULL)
matches any value in a specified list of value.
(d) COUNT(NULL)
14. Which of the following is the correct order of a Ans.(a) All aggregate functions exclude NULL values while
SQL statement? performing the operation and COUNT(*) is an aggregate
(a) SELECT, GROUP By, WHERE, HAVING function.
(b) SELECT, WHERE, GROUP BY, HAVING
(c) SELECT, HAVING, WHERE, GROUP BY
21. What is the meaning of “GROUP BY” clause in
(d) SELECT, WHERE, HAVING, GROUP BY MySQL?
(a) Group data by column values
Ans.(b) In SQL statement, the WHERE clause always comes
before GROUP BY and HAVING clause always comes (b) Group data by row values
after GROUP BY. Hence, option (b) is correct. (c) Group data by column and row values
(d) None of the mentioned
15. …… provides statements for creation and deletion
Ans.(a) Through GROUP BY clause we can create groups
of the database tables, views. from a column of data in a table.
(a) DDL (b) DCL
(c) DML (d) TCL 22. Which clause is similar to “HAVING” clause in
Ans.(a) DDL (Data Definition Language) provides statements
MySQL?
for creation and deletion of database tables, views. (a) SELECT (b) WHERE
(c) FROM (d) None of the mentioned
16. Which of the following is not an aggregate Ans.(b) HAVING clause will act exactly same as WHERE
function? clause. i.e. filtering the rows based on certain conditions.
(a) AVG() (b) ADD()
(c) MAX() (d) COUNT() 23. Which clause is used with an “aggregate
Ans.(b) There is no aggregate function named ADD() but
functions”?
SUM() is an aggregate function which performs (a) GROUP BY (b) SELECT
mathematical sum of multiple rows having numerical (c) WHERE (d) Both (a) and (c)
values. Ans.(a) “GROUP BY” is used with an aggregate functions.
17. Which aggregate function returns the count of all 24. Which of the following join gives the intersection
rows in a specified table? of two tables?
(a) SUM() (b) DISTINCT() (a) Outer join (b) Inner join
(c) COUNT() (d) None of these (c) Equi join (d) None of these
Ans.(c) COUNT() function returns the total number of values Ans.(b) Inner join gives the intersection of two tables.
or rows of the specified field or column.
25. ……… is a simple SQL join condition that uses
18. In which function, NULL values are excluded from equal sign as a comparison operator.
the result returned? (a) Equi join (b) Non-equi join
(a) SUM() (b) MAX() (c) Both (a) and (b) (d) None of the above
(c) MIN() (d) All of these Ans.(a) Equi join is a simple SQL join condition that uses
equal sign as a comparison operator.
80 CBSE Term II Computer Science XII

(iii) (d) The ALTER command can be used to make any


l
Case Based MCQs changes to the structure of a table.
26. Direction Read the case and answer the following (iv) (a) The varchar is a variable length data type that
questions. can used for columns storing string/character type of
data.
Ronita wants to store the data of some products in a
(v) (b) With the ALTER TABLE command the
table product as follows COLUMN clause is optional, in adding columns to a
Table : Product table.
PNo PName Qty Date_Of_Mfg 27. Table: Book_Information Table: Sales
P01 Pencil 20 2020-09-01 Column Name Column Name
P02 Eraser 5 1990-09-11 Book_ID Store_ID
P03 Book 16 2000-04-03 Book_Title Sales_Date
P04 Notebook 15 2016-12-11 Price Sales_Amount
P05 Color 10 2015-02-04
Basis on above table information, answer the
She also wants to perform some operations and following questions.
manipulations on the table . Help her to find the (i) Which SQL statement allows you to find the
solutions of following questions. highest price from the table Book_Information?
(i) A command that displays the details of all the (a) SELECT Book_ID,Book_Title,MAX(Price) FROM
products will be Book_Information;
(a) SELECT * FROM Product; (b) SELECT MAX(Price) FROM Book_Information;
(b) SHOW * FROM Product; (c) SELECT MAXIMUM(Price) FROM Book_Information;
(c) DISPLAY * FROM Product; (d) SELECT Price FROM Book_Information ORDER BY Price
(d) SELECT ALL details FROM Product; DESC;
(ii) The default date format in which date has to be (ii) Which SQL statement allows you to find sales
stored in MySQL is amount for each store?
(a) DD-MM-YYYY (b) DD-YY-MM (a) SELECT Store_ID, SUM(Sales_Amount) FROM Sales;
(c) MM-YY-DD (d) YYYY-MM-DD (b) SELECT Store_ID, SUM(Sales_Amount) FROM Sales
(iii) Which command she can use to add a new column ORDER BY Store_ID;
to the table? (c) SELECT Store_ID, SUM(Sales_Amount) FROM Sales
(a) INSERT (b) UPDATE GROUP BY Store_ID;
(c) ADD COLUMN (d) ALTER
(d) SELECT Store_ID, SUM(Sales_Amount) FROM Sales
(iv) Suggest her a proper data type for the “PName” HAVING UNIQUE Store_ID;
column.
(a) Varchar
(iii) Which SQL statement lets you to list all store name
whose total sales amount is over 5000 ?
(b) Double
(a) SELECT Store_ID, SUM(Sales_Amount) FROM Sales
(c) Float GROUP BY Store_ID HAVING SUM(Sales_Amount) >
(d) Integer 5000;
(v) She is confused whether she has to use the (b) SELECT Store_ID, SUM(Sales_Amount) FROM Sales
“COLUMN” clause with the ALTER TABLE GROUP BY Store_ID HAVING Sales_Amount > 5000;
command to add a column to the table. What (c) SELECT Store_ID, SUM(Sales_Amount) FROM Sales
should she do ? WHERE SUM(Sales_Amount) > 5000 GROUP BY Store_ID;
(a) COLUMN clause is must. (d) SELECT Store_ID, SUM(Sales_Amount) FROM Sales
(b) COLUMN clause is optional. WHERE Sales_Amount > 5000 GROUP BY Store_ID;
(c) COLUMN clause is must for adding integer columns
only.
(iv) Which SQL statement lets you find the total
number of stores in the SALES table?
(d) None of the above
Ans. (i) (a) SELECT * FROM Product;
(ii) (d) By default, MySQL stores date in YYYY-MM-DD
format.
CBSE Term II Computer Science XII 81

(a) SELECT COUNT(Store_ID) FROM Sales; 2. How is char data type different from varchar data
(b) SELECT COUNT(DISTINCT Store_ID) FROM type? (NCERT)
Sales; Ans. Differences between char data type and varchar data type
(c) SELECT DISTINCT Store_ID FROM Sales; are
(d) SELECT COUNT(Store_ID) FROM Sales GROUP BY Char Varchar
Store_ID;
It is fixed length. It is variable length.
(v) Which SQL statement allows you to find the total
Wastage of memory. Memory usage only as per data size.
sales amount for Store_ID 25 and the total sales
amount for Store_ID 45? Less useful. Better data type.
(a) SELECT Store_ID, SUM(Sales_Amount) FROM Sales WHERE
3. Explain the use of ORDER BY clause.
Store_ID IN ( 25, 45) GROUP BY Store_ID;
Ans.The ORDER BY clause is used to arrange the records in
(b) SELECT Store_ID, SUM(Sales_Amount) FROM Sales ascending or descending order. Data present in a table
GROUP BY Store_ID HAVING Store_ID IN ( 25, 45); can be arranged as per requirement on a specific field in
ascending or descending order. The default is ascending
(c) SELECT Store_ID, SUM(Sales_Amount) FROM Sales order. To arrange in descending order the DESC clause
WHERE Store_ID IN (25,45); is to be used. To arrange in ascending order ASC may be
used.
(d) SELECT Store_ID, SUM(Sales_Amount) FROM Sales
e.g. SELECT * FROM Employee ORDER BY EMP_SALARY DESC;
WHERE Store_ID = 25 AND Store_ID =45 GROUP BY
The above command arranges the records in descending
Store_ID; order of salary.
Ans. (i) (b) SELECT MAX(Price) FROM Book_Information;
4. Write the queries for the following questions using
(ii) (c) SELECT Store_ID, SUM(Sales_Amount) FROM Sales the table Product with the following fields.
GROUP BY Store_ID; (P_ Code, P_Name, Qty, Price)
(iii) (a) SELECT Store_ID, SUM(Sales_Amount) FROM Sales (i) Display the price of product having code as P06.
GROUP BY Store_ID HAVING SUM(Sales_Amount) >
5000; (ii) Display the name of all products with quantity
greater than 50 and price less than 500.
(iv) (d) SELECT COUNT(Store_ID) FROM Sales GROUP BY
Ans. (i) SELECT Price FROM Product WHERE
Store_ID;
P_Code=“P06”;
(v) (b) SELECT Store_ID, SUM(Sales_Amount) FROM Sales The criteria of the records that are to be displayed
GROUP BY Store_ID HAVING Store_ID IN ( 25, can be specified with WHERE clause of SQL.
45); (ii) SELECT P_Name FROM Product WHERE Qty>50 AND
Price<500;
PART 2 The criteria of the records that are to be displayed
can be specified with WHERE clause of SQL. Here,
the condition is quantity > 50 and price<500 .
Subjective Questions 5. Is it compulsory to provide values for all columns
of a table while adding records? Give an example.
l
Short Answer Type Questions Ans.No it is not compulsory to provide values for all columns
1. Differentiate between ALTER and UPDATE of a table while adding records. We can use NULL
commands in SQL. (NCERT) values wherever values are missing.
Ans. Differences between ALTER and UPDATE commands e.g. INSERT INTO Employee VALUES
(1,NULL,“Sales”,89000);
in SQL are
6. Amit wrote the command to create a table
ALTER command UPDATE command “Student” as :
It belongs to DDL It belongs to DML category. CREATE TABLE Student(RollNo integer, Name
category. varchar(20), Marks float(8,2));
It changes the structure It modifies data of the table. What does (8,2) mean here?
of the table. Ans.While specifying float columns in a table the width and
Columns can be added, Data can be changed, updated the number of decimals have to be specified. Here 8 is
modified , deleted etc. with values and expressions. the total width and 2 is the number of decimal places for
the Marks column.
82 CBSE Term II Computer Science XII

7. Rakesh wants to increase the price of some of the SELECT DISTINCT CLASS FROM Student ;
products by 20% , of his store whose price is less This displays only the unique classes.
than 200. Assuming the following structure , what 12. What do you mean by an operator? Name any four
will be the query?
operators used in queries.
PNo PName Quality Price Ans.An operator is a component of an expression that
represents the action that should be taken over a set of
Ans. UPDATE ITEM SET Price=Price + Price * 0.2 WHERE values.
Price<200 ; Four operators used in queries are
The UPDATE command updates data of a table . While (i) Arithmetic operators
updating, the expression for update value can be (ii) Comparison operators
assigned to the updating field. The records to be updated (iii) Boolean/Logical operators
can be specified as WHERE condition. (iv) Between operator
8. Write the use of LIKE clause and a short
explanation on the two characters used with it.
13. How NOT operator is used with WHERE clause?
Give an example.
Ans.This operator is used to search a specified pattern in a
Ans.The WHERE clause is used to retrieve some given data
column. It is useful when you want to search rows to according to the condition and NOT operator reverses
match a specific pattern or when you do not know the the result of it.
entire value.The SQL LIKE clause is used to compare a For example,
value to similar values using wildcard characters.
mysql>SELECT Name, Class, Games FROM
We describe patterns by using two special wildcard Student_table WHERE NOT Games = ‘FootBALL’;
characters, given below:
(i) The per cent sign (%) is used to match any 14. What are the functions of ALTER TABLE
substring. command?
(ii) The underscore (_) is used to match any single Ans.The main functions of ALTER TABLE command are
character. (i) Add or drop columns.
The symbols can also be used in combinations. (ii) Change the column definition of a column.
(iii) Add or drop constraint.
9. Given the command below. (iv) Rename a column.
DELETE FROM Toys WHERE ToyName LIKE “S_t%”; 15. Write syntax of the conditions given below.
Which records will be deleted by the above (i) Add a column in a table.
command? (ii) Delete a column from a table.
Ans.The command has a LIKE clause with “S_t%” which Ans. (i) ALTER TABLE<table_name>ADD
means all the toy names that start with the letter ‘S’ and <column_name>datatype<value>;
has 3rd letter as ‘t’ will deleted. (ii) ALTER TABLE<table_name>DROP
10. In the following query how many rows will be COLUMN<column_name>;
deleted? (NCERT) 16. Consider the following table PREPAID. Write
DELETE Student MySQL commands for the statements given below.
WHERE Student_ID=109;
S_No C_Name Model Connection
(Assuming a Student table with primary key
Student_ID) 1. Sita Nokia Airtel
Ans.DELETE FROM Student WHERE Student_ID=109; 2. Geeta Samsung Idea
Here, the “FROM” clause is missing , so the command 3. Ritesh LG BSNL
will produce an error. 4. Jayant Micromax Reliance
11. If the value in the column is repeatable, how do
you find out the unique values? (NCERT)
(i) DELETE a column name Model.
Ans.The DISTINCT clause in SQL is used to display only (ii) DELETE a customer record where connection
distinct values in a column of a table. Hence, if the type is BSNL.
column allows duplicate values the unique values can be Ans. (i) mysql> ALTER TABLE PREPAID DROP Model;
extracted using the DISTINCT clause. (ii) mysql> DELETE FROM PREPAID WHERE Connection =
‘BSNL’;
CBSE Term II Computer Science XII 83

17. What will be the output of the following queries on FROM Employee
the basis of EMPLOYEE table? GROUP BY Deptcode;
Table : EMPLOYEE 21. Consider the following table Employee :
Emp_Id Name Salary Table : Employee
E01 Siya 54000 100 Steven King Sking 1987-06-17 AD_PRES 24000.00 90
E02 Joy NULL 101 Neena Kochhar Nkochhar 1987-06-18 AD_VP 17000.00 90
E03 Allen 32000
102 Lex De Haan Ldehaan 1987-06-19 AD_VP 9000.00 60
E04 Neev 42000
103 Alexander Hunold Ahunold 1987-06-20 IT_PROG 6000.00 60
(i) SELECT Salary + 100 FROM EMPLOYEE
104 Bruce Ernst Bernst 1987-06-21 IT_PROG 4800.00 60
WHERE Emp_Id = ‘E02’;
(ii) SELECT Name FROM EMPLOYEE 105 David Austin Daustin 1987-06-22 IT_PROG 4800.00 60

WHERE Emp_Id = ‘E04’; 106 Valli Pataballa Vpata- 1987-06-23 IT_PROG 4800.00 100
balla
Ans.The output of the following queries
+ + + +
Salary+100 Name Write a query to get the total salary, maximum,
(i) + + (ii) + + minimum, average salary of employees (Job_ID
NULL Neev wise), for Dept_ID 90 only.
+ + + +
Ans.SELECT Job_ID, SUM(Salary), AVG(Salary),
18. What are the aggregate functions in SQL?
MAX(Salary), MIN(Salary)
Ans.Aggregate function is a function where the values of
multiple-rows are grouped together as input on certain FROM Employee
criteria to form a single value of more significant WHERE Dept_ID = ‘90’
meaning. Some aggregate functions used in SQL are GROUP BY Job_ID;
SUM ( ), AVG( ), MIN(), etc. l
Long Answer Type Questions
19. What is the purpose of GROUP BY clause in
MySQL? How is it different from ORDER BY 22. What is the differences between HAVING clause
clause? [CBSE 2012] and WHERE clause?
Ans.The GROUP BY clause can be used to combine all those Ans. Differences between HAVING clause and WHERE
records that have identical value in a particular field or a clause are
group of fields. WHERE clause HAVING clause
Whereas, ORDER BY clause is used to display the
WHERE clause is used to HAVING clause is used to
records either in ascending or descending order based on
filter the records from the filter record from the groups
a particular field. For ascending order ASC is used and table based on the specified based on the specified
for descending order, DESC is used. The default order is condition. condition.
ascending order.
WHERE clause HAVING clause implements
20. Gopi Krishna is using a table Employee. It has the implements in row in column operation.
following columns : operation.

Code, Name, Salary, Dept_code WHERE clause cannot HAVING clause can contain
contain aggregate function. aggregate function.
He wants to display maximum salary department
wise. He wrote the following command : WHERE clause can be HAVING clause can only be
used with SELECT, used with SELECT statement.
SELECT Deptcode, Max(Salary) FROM Employee; UPDATE, DELETE
But he did not get the desired result. statement.
Rewrite the above query with necessary changes to WHERE clause is used HAVING clause is used with
help him get the desired output. [CBSE Delhi 2014] with single row function multiple row function like
like UPPER, LOWER etc. SUM, COUNT etc.
Ans.SELECT Deptcode, Max(Salary)
84 CBSE Term II Computer Science XII

23. Answer the questions (i) to (v) on the basis of the (iv) SELECT Name, Price, SName
following tables SHOPPE and ACCESSORIES. FROM ACCESSORIES A, SHOPPE S
Table : SHOPPE WHERE A.Id = S.Id;
but this query enable to show the result because
Id SName Area A.Id and S.Id are not identical.
S001 ABC Computeronics CP (v) SELECT Name From
S002 All Infotech Media GK II ACCESSORIES
S003 Tech Shoppe CP WHERE Price>1000;

S004 Geeks Tecno Soft Nehru Place 24. Consider the following tables STORE and answer
S005 Hitech Tech Store Nehru Place
the questions:
Table: STORE
Table : ACCESSORIES
ItemNo Item Scode Qty Rate LastBuy
No Name Price Id
2005 Sharpener Classic 23 60 8 31-JUN-09
A01 Mother 12000 S01
Board 2003 Balls 22 50 25 01-FEB-10
A02 Hard Disk 5000 S01 2002 Gel Pen Premium 21 150 12 24-FEB-10
A03 Keyboard 500 S02 2006 Gel Pen Classic 21 250 20 11-MAR-09
A04 Mouse 300 S01 2001 Eraser Small 22 220 6 19-JAN-09
A05 Mother 13000 S02 2004 Eraser Big 22 110 8 02-DEC-09
Board 2009 Ball Pen 0.5 21 180 18 03-NOV-09
A06 Keyboard 400 S03
A07 LCD 6000 S04 Write SQL commands for the following statements:
T08 LCD 5500 S05 (i) To display details of all the items in the STORE
table in ascending order of LastBuy.
T09 Mouse 350 S05
(ii) To display ItemNo and Item name of those
T10 Hard Disk 4500 S03 items from STORE table, whose Rate is more
(i) To display Name and Price of all the Accessories than ` 15.
in ascending order of their Price. (iii) To display the details of those items whose Supplier
(ii) To display Id and SName of all Shoppe located in code (Scode) is 22 or Quantity in Store (Qty) is
Nehru Place. more than 110 from the table STORE.
(iii) To display Minimum and Maximum Price of each (iv) To display minimum rate of items for each
Name of Accessories.
Supplier individually as per Scode from the table
(iv) To display Name, Price of all Accessories and STORE.
their respective SName, where they are
available. (v) To display the item with its quantity which
(v) To display name of accessories whose price is include pen in their name.
greater than 1000. Ans. (i) SELECT * FROM STORE ORDER BY LastBuy;
Ans. (i) SELECT Name, Price (ii) SELECT ItemNo, Item FROM STORE WHERE Rate>15;
FROM ACCESSORIES (iii) SELECT * FROM STORE WHERE Scode = 22 OR
ORDER BY Price; Qty>110;
(ii) SELECT Id, SName (iv) SELECT MIN(Rate) FROM STORE GROUP BY Scode;
FROM SHOPPE (v) SELECT Item, Qty FROM STORE WHERE Item LIKE
WHERE Area = ‘Nehru Place’; ‘%Pen%’;
(iii) SELECT MIN(Price) “Minimum Price”,
MAX(Price) “Maximum Price”, Name 25. Consider the following tables STUDENT and
FROM ACCESSORIES STREAM. Write SQL commands for the
GROUP BY Name; statements (i) to (v).
CBSE Term II Computer Science XII 85

Table : STUDENT 26. Consider the following tables GARMENT and


SCODE NAME AGE STRCDE POINTS GRADE FABRIC. Write SQL commands for the statements
(i) to (v).
101 Amit 16 1 6 NULL
Table : GARMENT
102 Arjun 13 3 4 NULL
GCODE DESCRIPTION PRICE FCODE READYDATE
103 Zaheer 14 2 1 NULL
10023 PENCIL SKIRT 1150 F03 19-DEC-08
105 Gagan 15 5 2 NULL
10001 FORMAL SHIRT 1250 F01 12-JAN-08
108 Kumar 13 6 8 NULL
10012 INFORMAL 1550 F02 06-JUN-08
109 Rajesh 17 5 8 NULL SHIRT
110 Naveen 13 3 9 NULL 10024 BABY TOP 750 F03 07-APR-07
113 Ajay 16 2 3 NULL 10090 TULIP SKIRT 850 F02 31-MAR-07
115 Kapil 14 3 2 NULL 10019 EVENING GOWN 850 F03 06-JUN-08
120 Gurdeep 15 2 6 NULL 10009 INFORMAL 1500 F02 20-OCT-08
PANT
Table : STREAM
10007 FORMAL PANT 1350 F01 09-MAR-08
STRCDE STRNAME 10020 FROCK 850 F04 09-SEP-07
1 SCIENCE+COMP 10089 SLACKS 750 F03 20-OCT-08
2 SCIENCE+BIO
Table : FABRIC
3 SCIENCE+ECO
FCODE TYPE
4 COMMERCE+MATH
S F04 POLYSTER
F02 COTTON
5 COMMERCE+SOCIO
F03 SILK
6 ARTS+MATHS
F01 TERELENE
7 ARTS+SOCIO
(i) To display GCODE and DESCRIPTION of each
(i) To display the name of streams in alphabetical GARMENT in descending order of GCODE.
order from table STREAM. (ii) To display the details of all the GARMENTs,
(ii) To display the number of students whose which have READYDATE in between
POINTS are more than 5. 08-DEC-07 and 16-JUN-08 (inclusive of both
(iii) To update GRADE to ‘A’ for all those students, the dates).
who are getting more than 8 as POINTS. (iii) To display the average PRICE of all the
(iv) ARTS+MATHS stream is no more available. GARMENTs. Which are made up of FABRIC
with FCODE as F03.
Make necessary change in table STREAM.
(iv) To display FABRIC wise highest and lowest
(v) To display student’s name whose stream name is
price of GARMENTs from GARMENT table.
science and computer.
(Display FCODE of each GARMENT alongwith
Ans. (i) SELECT STRNAME FROM STREAM ORDER BY STRNAME;
highest and lowest price.)
(ii) SELECT COUNT(*) FROM STUDENT WHERE POINTS > 5;
(v) To display garment’s description with their price
(iii) UPDATE STUDENT SET GRADE = ‘A’ WHERE POINTS >
whose fabric is silk.
8;
Ans. (i) SELECT GCODE, DESCRIPTION FROM GARMENT ORDER
(iv) DELETE FROM STREAM WHERE STRNAME
BY GCODE DESC;
= ‘ARTS + MATHS’;
(ii) SELECT*FROM GARMENT
(v) SELECT NAME FROM STUDENT
WHERE READYDATE BETWEEN ‘08-DEC-07’ AND
WHERE STUDENT.STRCDE = STREAM.STRCDE
‘16-JUN-08’;
AND STRNAME = “SCIENCE + COMP”;
(iii) SELECT AVG(PRICE) FROM GARMENT WHERE FCODE =
‘F03’;
86 CBSE Term II Computer Science XII

(iv) SELECT FCODE, MAX(PRICE), MIN(PRICE) FROM (v) SELECT * FROM RECIPIENT
GARMENT GROUP BY FCODE; WHERE RecCity = “Mumbai”;
(v) SELECT DESCRIPTION, PRICE FROM GARMENT 28. Write the SQL commands for (i) to (v) on the basis
WHERE GARMENT.FCODE = FABRIC.FCODE of the table HOSPITAL.
AND TYPE = “SILK”; Table : HOSPITAL
27. Consider the following tables. Write SQL
No. Name Age Department Dateofadm Charges Sex
commands for the statements (i) to (v).
Table : SENDER 1 Sandeep 65 Surgery 23/02/98 300 M

SenderID SenderName SenderAddress SenderCity 2 Ravina 24 Orthopaedic 20/01/98 200 F


ND01 R Jain 2, ABC Appts New Delhi 3 Karan 45 Orthopaedic 19/02/98 200 M
MU02 H Sinha 12, Newtown Mumbai
4 Tarun 12 Surgery 01/01/98 300 M
MU15 S Jha 27/A, Park Street Mumbai
5 Zubin 36 ENT 12/01/98 250 M
ND50 T Prasad 122-K, SDA New Delhi
6 Ketaki 16 ENT 24/02/98 300 F
Table : RECIPIENT
7 Ankita 29 Cardiology 20/02/98 800 F
RecID SenderID RecName RecAddress RecCity
8 Zareen 45 Gynaecology 22/02/98 300 F
KO05 ND01 R Bajpayee 5, Central Avenue Kolkata
ND08 MU02 S Mahajan 116, A Vihar New Delhi 9 Kush 19 Cardiology 13/01/98 800 M

MU19 ND01 H Singh 2A, Andheri East Mumbai 10 Shailya 31 Nuclear 19/02/98 400 M
Medicine
MU32 MU15 P K Swamy B5, C S Terminus Mumbai
ND48 ND50 S Tripathi 13, B1 D, New Delhi (i) To show all information about the patients of
Mayur Vihar Cardiology Department.
(i) To display the names of all Senders from (ii) To list the name of female patients, who are in
Mumbai. Orthopaedic Department.
(ii) To display the RecID, SenderName, (iii) To list names of all patients with their date of
SenderAddress, RecName, RecAddress for every admission in ascending order.
Recipient. (iv) To display Patient’s Name, Charges, Age for male
patients only.
(iii) To display Recipient details in ascending order of
RecName. (v) To display name of doctor are older than 30 years
and charges for consultation fee is more than
(iv) To display number of Recipients from each City. 500.
(v) To display the detail of recipients who are in
Ans. (i) SELECT * FROM HOSPITAL WHERE Department =
Mumbai. ‘Cardiology’;
Ans. (i) SELECT SenderName FROM SENDER WHERE SenderCity
(ii) SELECT Name FROM HOSPITAL WHERE Department =
= ‘Mumbai’;
‘Orthopaedic’ AND Sex
(ii) SELECT RecID, SenderName, SenderAddress, = ‘F’;
RecName, RecAddress
(iii) SELECT Name FROM HOSPITAL ORDER BY Dateofadm;
FROM RECIPIENT, SENDER WHERE
(iv) SELECT Name, Charges, Age FROM HOSPITAL WHERE
RECIPIENT.SenderID = SENDER.SenderID;
Sex = ‘M’;
(iii) SELECT * FROM RECIPIENT ORDER BY RecName;
(v) SELECT NAME FROM HOSPITAL WHERE Age>30 AND
(iv) SELECT COUNT(*) AS “No. of Recipients”,
RecCity FROM RECIPIENT Charges>500;
GROUP BY RecCity;
CBSE Term II Computer Science XII 87

29. Write SQL commands for (i) to (v) on the basis of (iv) INSERT INTO INTERIORS VALUES (14,‘TrueIndian’,
table INTERIORS. ‘Office Table’,
‘25/03/03’,15000,20);
Table : INTERIORS
(v) SELECT ITEMNAM, PRICE FROM INTERIORS WHRE
DATEOF DISCO- DISCOUNT>20;
No. ITEMNAME TYPE PRICE
STOCK UNT
30. Given the following tables for a database LIBRARY.
1 Red rose Double Bed 23/02/02 32000 15
Table : BOOKS
2 Soft touch Baby cot 20/01/02 9000 10 Book_ Author_
Book_Id Publishers Price Type Qty
3 Jerry’s home Baby cot 19/02/02 8500 10 Name Name
F0001 The William First Publ 750 Fiction 10
4 Rough wood Office Table 01/01/02 20000 20
Tears Hopkins
5 Comfort zone Double Bed 12/01/02 15000 20 F0002 Thunder Anna First Publ 700 Fiction 5
6 Jerry look Baby cot 24/02/02 7000 19 bolts Roberts
T0001 My Brain & EPB 250 Text 10
7 Lion king Office Table 20/02/02 16000 20 First Brooke
8 Royal tiger Sofa 22/02/02 30000 25 C++
T0002 C++ A.W. TDH 325 Text 5
9 Park sitting Sofa 13/12/01 9000 15
Brainwo Rossaine
10 Dine Paradise Dining Table 19/02/02 11000 15 rks

11 White Wood Double Bed 23/03/03 20000 20 C0001 Fast Lata EPB 350 Cookery 8
Cook Kapoor
12 James 007 Sofa 20/02/03 15000 15
Table : ISSUED
13 Tom look Baby cot 21/02/03 7000 10
Book_Id Quantity_Issued
F0001 3
(i) To show all information about the Sofa from the
T0001 1
INTERIORS table.
C0001 5
(ii) To list the ITEMNAME, which are priced at
more than 10000 from the INTERIORS table. Write SQL queries for (i) to (v).
(iii) To list ITEMNAME and TYPE of those items, in (i) To show Book name, Author name and Price of
which DATEOFSTOCK is before 22/01/02 from books of EPB Publishers.
the INTERIORS table in descending order of (ii) To list the names from books of Fiction type.
ITEMNAME. (iii) To display the names and price of the books in
descending order of their price.
(iv) To insert a new row in the INTERIORS table
with the following data (iv) To increase the price of all books of First Publ
Publishers by 50.
{14, ‘TrueIndian’, ‘Office Table’,
(v) To display the detail of book whose quantity less
‘25/03/03’, 15000, 20}
than 10.
(v) To display the name of item with their price Ans. (i) SELECT Book_Name, Author_Name, Price FROM
which have discount more than 20. BOOKS WHERE Publishers = ‘EPB’;
Ans. (i) SELECT * FROM INTERIORS WHERE TYPE (ii) SELECT Book_Name FROM BOOKS WHERE Type =
= ‘Sofa’; ‘Fiction’;
(ii) SELECT ITEMNAME FROM INTERIORS WHERE PRICE > (iii) SELECT Book_Name, Price FROM BOOKS ORDER BY
Price DESC;
10000;
(iv) UPDATE BOOKS SET Price = Price + 50
(iii) SELECT ITEMNAME, TYPE FROM INTERIORS WHERE
WHERE Publishers = ‘First Publ’;
DATEOFSTOCK < ‘22/01/02’
(v) SELECT *FROM BOOKS
ORDER BY ITEMNAME DESC; WHERE Qty<10;
88 CBSE Term II Computer Science XII

31. Write SQL commands for (i) to (v) on the basis of (i) To select all the information of family, whose
table STUDENT Occupation is Service.
(ii) To list the name of family, where female
Table : STUDENT members are more than 3.
SNO NAME STREAM FEES AGE SEX (iii) To list all names of family with income in
1 ARUN KUMAR COMPUTER 750.00 17 M ascending order.
(iv) To count the number of family, whose income is
2 DIVYA JENEJA COMPUTER 750.00 18 F less than 10000.
3 KESHAR BIOLOGY 500.00 16 M
MEHRA
(v) To display the detail of family whose income is
more than 10000 and occupation is mixed type.
4 HARISH SINGH ENG. DR 350.00 18 M
Ans. (i) SELECT * FROM FAMILY WHERE Occupation =
5 PRACHI ECONOMICS 300.00 19 F ‘Service’;
6 NISHA ARORA COMPUTER 750.00 15 F (ii) SELECT Name FROM FAMILY WHERE FemaleMembers >
7 DEEPAK ECONOMIC 300.00 16 M 3;
KUMAR S (iii) SELECT Name, Income FROM FAMILY ORDER BY
Income;
8 SARIKA BIOLOGY 500.00 15 F
VASWANI (iv) SELECT COUNT(*) FROM FAMILY WHERE Income <
10000;
(i) List the name of all the students, who have taken (v) SELECT *FROM FAMILY
stream as COMPUTER. WHERE INCOME > 10000
(ii) To count the number of female students. AND Occupation = “Mixed”;
(iii) To display the number of students stream wise. 33. Consider the following tables PRODUCT and
(iv) To display all the records in sorted order of CLIENT. Write SQL commands for the statement
name. (i) to (v).
(v) To display the stream of student whose name is Table : PRODUCT
Harish.
P_ID ProductName Manufacturer Price
Ans. (i) SELECT NAME FROM STUDENT WHERE STREAM
=‘COMPUTER’; TP01 Talcom Powder LAK 40
(ii) SELECT COUNT(*) FROM STUDENT WHERE SEX = ‘F’; FW05 Face Wash ABC 45
(iii) SELECT STREAM, COUNT(*) FROM STUDENT GROUP BY BS01 Bath Soap ABC 55
STREAM;
SH06 Shampoo XYZ 120
(iv) SELECT * FROM STUDENT ORDER BY NAME;
(v) SELECT STREAM FROM STUDENT FW12 Face Wash XYZ 95
WHERE NAME LIKE “%HARISH%”;
Table : CLIENT
32. Given the following family relation. Write SQL
commands for questions (i) to (v) based on the table C_ID ClientName City P_ ID
FAMILY 01 Cosmetic Shop Delhi FW05
Table : FAMILY
06 Total Health Mumbai BS01
Female Male 12 Live Life Delhi SH06
No. Name Income Occupation
Members Members
15 Pretty Woman Delhi FW12
1 Mishra 3 2 7000 Service
16 Dreams Bengaluru TP01
2 Gupta 4 1 50000 Business
3 Khan 6 3 8000 Mixed (i) To display the details of those Clients, whose
4 Chaddha 2 2 25000 Business City is Delhi.
5 Yadav 7 2 20000 Mixed (ii) To display the details of products, whose Price is
6 Joshi 3 2 14000 Service
in the range of 50 to 100 (both values included).
7 Maurya 6 3 5000 Farming
(iii) To display the ClientName, City from table
CLIENT and ProductName and Price from table
8 Rao 5 2 10000 Service PRODUCT, with their corresponding matching
P_ID.
CBSE Term II Computer Science XII 89

(iv) To increase the Price of all products by 10. (iv) Display the highest consultation fee among all
(v) To display the product detail whose male doctors.
manufacturer is ABC and price less than 50. (v) To display the detail of doctor who have
Ans. (i) SELECT * FROM CLIENT WHERE City =‘Delhi’; experience more than 12 years.
(ii) SELECT * FROM PRODUCT WHERE Price BETWEEN 50 Ans. (i) SELECT NAME FROM DOCTOR WHERE DEPT =
AND 100; ‘MEDICINE’ AND EXPERIENCE > 10;
(iii) SELECT ClientName, City, ProductName, Price (ii) SELECT AVG(BASIC + ALLOWANCE) FROM SALARY
FROM CLIENT, PRODUCT WHERE SALARY.ID IN(SELECT ID FROM DOCTOR WHERE
WHERE CLIENT.P_ID = PRODUCT.P_ID; DEPT = ‘ENT’);
(iv) UPDATE PRODUCT SET Price = Price + 10; (iii) SELECT MIN(ALLOWANCE) FROM SALARY WHERE
SALARY.ID IN(SELECT ID FROM DOCTOR WHERE SEX =
(v) SELECT *FROM PRODUCT
‘F’);
WEHRE Manufacturer = “ABC”
AND Price < 50; (iv) SELECT MAX(CONSULTATION) FROM SALARY WHERE
SALARY.ID IN(SELECT ID FROM DOCTOR WHERE SEX =
34. Study the following tables DOCTOR and SALARY ‘M’);
and write SQL commands for the questions (i) to (v) SELECT * FROM DOCTOR
(v). WHERE EXPERIENCE>12;
Table : DOCTOR
35. Study the following tables FLIGHTS and FARES
ID NAME DEPT SEX
EXPERI-E and write SQL commands for the questions (i) to
NCE (iv).
101 John ENT M 12 Table : FLIGHTS
104 Smith ORTHOPEDIC M 5
FL_ NO STARTING ENDING NO_FLIGHT NO_STOPS
107 George CARDIOLOGY M 10
IC301 MUMBAI DELHI 8 0
114 Lara SKIN F 3
IC799 BENGALURU DELHI 2 1
109 K George MEDICINE F 9
105 Johnson ORTHOPEDIC M 10 MC101 INDORE MUMBAI 3 0
117 Lucy ENT F 3 IC302 DELHI MUMBAI 8 0
111 Bill MEDICINE F 12 AM812 KANPUR BENGALURU 3 1
130 Morphy ORTHOPEDIC M 15 IC899 MUMBAI KOCHI 1 4
Table : SALARY AM501 DELHI TRIVANDRU 1 5
M
ID BASIC ALLOWANCE CONSULTATION
MU499 MUMBAI MADRAS 3 3
101 12000 1000 300
IC701 DELHI AHMEDABAD 4 0
104 23000 2300 500
107 32000 4000 500 Table : FARES
114 12000 5200 100
FL_NO AIRLINES FARE TAX%
109 42000 1700 200
IC701 INDIAN 6500 10
105 18900 1690 300
AIRLINES
130 21700 2600 300
MU499 SAHARA 9400 5
(i) Display NAME of all doctors who are in AM501 JET AIRWAYS 13450 8
MEDICINE department having more than IC899 INDIAN 8300 4
10yrs experience from the table DOCTOR. AIRLINES
(ii) Display the average salary of all doctors working IC302 INDIAN 4300 10
in ENT department using the tables DOCTOR AIRLINES
and SALARY. SALARY = BASIC + IC799 INDIAN 10500 10
ALLOWANCE. AIRLINES
(iii) Display the minimum ALLOWANCE of female MC101 DECCAN 3500 4
doctors. AIRLINES
90 CBSE Term II Computer Science XII

(i) Display FL_NO and NO_FLIGHT from (c) SELECT*FROM SPORTS ORDER NAME;
KANPUR to BENGALURU from the table (d) SELECT*FROM SPORTS ORDER BY NAME;
FLIGHTS. Ans. (i) SELECT GAME1, GAME2 FROM SPORTS WHERE NAME
(ii) Arrange the contents of the table FLIGHTS in LIKE ‘A%’;
the ascending order of FL_NO. (ii) ALTER TABLE SPORTS ADD(MARKS NUMBER(3));
(iii) Display the FL_NO and fare to be paid for the (iii) UPDATE SPORTS SET MARKS = 200
flights from DELHI to MUMBAI using the WHERE GRADE = ‘A’ OR GRADE = ‘B’ OR GRADE1 =
tables FLIGHTS and FARES, where the fare to ‘A’ OR GRADE1 = ‘B’;
be paid = FARE + FARE * TAX % 100. (iv) (d) SELECT * FROM SPORTS ORDER BY NAME;
(iv) Display the minimum fare INDIAN AIRLINES 37. Write SQL commands for (i) to (iv) on the basis of
is offering from the table FARES. table EMPLOYEE
(v) To display the detail fares of Indian airlines. Table : EMPLOYEE
Ans. (i) SELECT FL_NO, NO_FLIGHT FROM FLIGHTS
S DATO
WHERE STARTING = ‘KANPUR’ AND ENDING = NAME BASIC DEPARTMENT AGE SEX
NO FAPP
‘BENGALURU’;
(ii) SELECT * FROM FLIGHTS ORDER BY FL_NO; 1 KARAN 8000 PERSONNEL 27/03/97 35 M
(iii) SELECT FL_NO, FARE + FARE * TAX%100 FROM FARES 2 DIVAKAR 9500 COMPUTER 20/01/98 34 M
WHERE FL_NO = (SELECT FL_No FROM FLIGHTS WHERE 3 DIVYA 7300 ACCOUNTS 19/02/97 34 F
STARTING = ‘DELHI’ AND ENDING = ‘MUMBAI’);
4 ARUN 8350 PERSONNEL 01/01/95 33 M
(iv) SELECT MIN(FARE) FROM FARES GROUP BY AIRLINES
HAVING AIRLINES = ‘INDIAN AIRLINES’; 5 SABINA 9500 ACCOUNTS 12/01/96 36 F
(v) SELECT * FROM FARES 6 JOHN 7400 FINANCE 24/02/97 36 M
WHERE AIRLINES = "Indian Airlines";
7 ROBERT 8250 PERSONNEL 20/02/97 39 M
36. Write SQL commands for (i) to (iv) on the basis of
8 RUBINA 9450 MAINTENANCE 22/02/98 37 F
the table SPORTS
Table : SPORTS 9 VIKAS 7500 COMPUTER 13/01/94 41 M

STUD-E GRA 10 MOHAN 9300 MAINTENANCE 19/02/98 37 M


CLASS NAME GAME1 GRADEGAME2
NTNO DE1
(i) Which command will be used to list the names of
10 7 Sameer Cricket B Swimming A
the employees, who are more than 34 years old
11 8 Sujit Tennis A Skating C sorted by NAME.
12 7 Kamal Swimming B Football B (a) SELECT NAME FROM EMPLOYEE WHERE AGE>34 ORDER
13 7 Veena Tennis C Tennis A BY NAME;

14 9 Archana Basketball A Cricket A (b) SELECT * FROM EMPLOYEE WHERE AGE>34 ORDER BY
NAME;
15 10 Arpit Cricket A Athletics C
(c) SELECT NAME FROM EMPLOYEE WHERE AGE>34;
(i) Display the games taken up by the students, (d) SELECT NAME FROM EMPLOYEE AGE>34 ORDER BY
NAME;
whose name starts with ‘A’.
(ii) Write a query to display a report, listing NAME,
(ii) Write a query to add a new column named
BASIC, DEPARTMENT and annual salary.
MARKS.
Annual salary equals to BASIC * 12.
(iii) Write a query to assign a value 200 for Marks for
all those, who are getting grade ‘B’ or grade ‘A’ in (iii) Insert the following data in the EMPLOYEE
both GAME1 and GAME2. table
(iv) Which command will be used to arrange the 11, ‘VIJAY’, 9300, ‘FINANCE’, ‘13/7/98’, 35, “M”
whole table in the alphabetical order of NAME? (iv) Write a query to count the number of employees,
(a) SELECT FROM SPORTS ORDER BY NAME; who are either working in PERSONNEL or
(b) SELECT*SPORTS ORDER BY NAME; COMPUTER department.
CBSE Term II Computer Science XII 91

Ans. (i) (a) SELECT NAME FROM EMPLOYEE WHERE AGE > 34 (i) Write a query to change the Basic salary to
ORDER BY NAME; 10500 of all those teachers from COLLEGE,
(ii) SELECT NAME, BASIC, DEPARTMENT, BASIC*12 “Annual who joined the COLLEGE after 01/02/89 and
Salary” FROM EMPLOYEE; are above the age of 50.
(iii) INSERT INTO EMPLOYEE VALUES(11, ‘VIJAY’, 9300, (ii) Write a query to display Name, Age and Basic
‘FINANCE’, ‘13/7/98’, 35,‘M’); of all those from COLLEGE, who belong to
(iv) SELECT COUNT(*) FROM EMPLOYEE Physics and Chemistry department only.
WHERE DEPARTMENT = ‘PERSONNEL’ OR DEPARTMENT =
(iii) Which command will be used to delete a row
‘COMPUTER’;
from table COLLEGE, in which NAME is
38. Write SQL commands for (i) to (iv) on the basis of VIREN?
table COLLEGE (iv) Insert the following data in the given table
Table : COLLEGE COLLEGE
No Name Age Department DateofJoin Basic Sex 11, ‘Saurav’, 50, ‘Chemistry’, ‘18/05/93’,
1 Shalaz 45 Biology 13/02/88 10500 M 12000, ‘M’
2 Sameera 54 Biology 10/01/90 9500 F Ans. (i) UPDATE COLLEGE SET Basic = 10500
WHERE DateofJoin>‘01/02/89’ AND Age>50;
3 Yagyen 43 Physics 27/02/98 8500 M
(ii) SELECT Name, Age, Basic FROM COLLEGE
4 Pratyush 34 Chemistry 11/01/93 7500 M WHERE Department =‘Physics’ OR
5 Aren 51 Mathematics 22/01/91 8500 M Department =‘Chemistry’;
6 Reeta 27 Chemistry 14/02/94 9000 F (iii) DELETE FROM COLLEGE WHERE Name
= ‘VIREN’;
7 Urvashi 29 Biology 10/02/93 8500 F
(iv) INSERT INTO COLLEGE VALUES (11, ‘Saurav’,
8 Teena 35 Mathematics 02/02/89 10500 F
50, ‘Chemistry’, ‘18/05/93’,
9 Viren 49 Mathematics 03/01/88 9000 M 12000, ‘M’);
10 Prakash 22 Physics 17/02/92 8000 M
Chapter Test
Multiple Choice Questions
1. Riya wants to remove a column “Name” from her table , which command she has to use?
(a) ALTER TABLE (b) CLEAR
(c) UPDATE (d) None of these
2. The clause with ALTER TABLE command that renames a column is
(a) RENAME (b) CHANGE
(c) DROP (d) CHANGENAME
3. We can use the aggregate functions in select list or the ........ clause of a select statement. But they cannot be used in a
........ clause.
(a) WHERE, HAVING (b) GROUP BY, HAVING
(c) HAVING, WHERE (d) GROUP BY, WHERE
4. Select correct SQL query from below to find the temperature in increasing order of all cites.
(a) SELECT city FROM weather ORDER BY temperature;
(b) SELECT city, temperature FROM weather;
(c) SELECT city, temperature FROM weather ORDER BY temperature;
(d) SELECT city, temperature FROM weather ORDER BY city;
5. The HAVING clause acts like a WHERE clause, but it identifies columns that meet a criterion, rather than rows.
(a) True (b) False
(c) Depend on query (d) Depend on column

Short Answer Type Questions


6. Explain usage of IS NULL and IS NOT NULL clauses. (NCERT)
7. With respect to the following table structure write queries for the following
GameID GName Type Players

(i) To display the details of games of “OUTDOOR” type.


(ii) To display GName and Players for games where players is more than 2.
8. Explain working of AND and OR operators in queries.
9. Write a query to display the Sum, Average, Highest and Lowest marks of the students grouped by subject and
sub-grouped by class.
10. The following query is producing an error. Identify the error and also write the correct query.
SELECT * FROM EMP ORDER BY NAME WHERE SALARY>=5000;
Long Answer Type Questions
11. With respect to the following table “BOOK” write SQL commands for the questions (i) to (iv).
Table : Book
BookID Bname Publisher Price DtofPub
B1 Science Fiction TMH 1200 2020-09-08
B2 Stories PHI 900 NULL
B3 Ramayana PHI 1700 NULL
B4 Beginners Oswal 1400 1990-12-03
Cooking

(i) Display details of books published before year 2000.


(ii) Display names and publishers of books whose price is less than 1000.
(iii) Display names of books who do not have a date of publication.
(iv) Increase price of all books by 200.
CBSE Term II Computer Science XII 93

12. Write SQL commands with respect to the Employee table given below.
Table : Employee
Eno Ename Dept Desig DtofJoin Salary
1 Jack Sales MGR 2012-09-12 89000
2 Priya Accts MGR 2005-04-22 56000
3 Ria Pers Clerk 2000-01-09 25000
4 Anil Pers Officer 1994-04-03 67000
5 Sumit Sales Officer NULL 19000
6 Akash Sales Officer NULL 20000

(i) Display name and department of employees whose name begins with” S”.
(ii) Display details of employees whose designation ends with “r”.
(iii) Display details of employees whose name has 1st letter “P” 3rd letter “i”.
(iv) Display name,deptartment and salary of employees whose department name ends with “s”.
13. Consider the following table GARMENT, write SQL commands for the statements (i) to (v). [CBSE Question Bank 2021]
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
10024 BABY TOP 750 F03 07-APR-07
10090 TULIP SKIRT 850 F02 31-MAR-07
10019 EVENING GOWN 850 F03 06-JUN-08
10009 INFORMAL PANT 1500 F02 20-OCT-08
10007 FORMAL PANT 1350 F01 09-MAR-08
10020 FROCK 850 F04 09-SEP-07
10089 SLACKS 750 F03 20-OCT-08

(i) To display GCODE and DESCRIPTION of each GARMENT in descending order of GCODE.
(ii) To display the details of all the GARMENT, which have READYDATE in between 08-DEC-07 and 16-JUN-08 (inclusive if both
the dates).
(iii) To display the average PRICE of all the GARMENT, which are made up of fabric with FCODE as F03.
(iv) To display fabric wise highest and lowest price of GARMENT from GARMENT table. (Display FCODE of each GARMENT
along with highest and lowest price).
(v) To display GCODE whose PRICE is more than 1000.

Answers For Detailed Solutions


Multiple Choice Questions Scan the code
1. (a) 2. (b) 3. (b) 4. (c) 5. (b)

You might also like