You are on page 1of 4

lOMoARcPSD|34467512

XII IP -SQL worksheet

Sql (MIT School of Distance Education)

Studocu is not sponsored or endorsed by any college or university


Downloaded by Deivanai K CS (vngs.pgt.deivanai@velammal.edu.in)
lOMoARcPSD|34467512

Class: XII [Worksheet on MY SQL]


1 Which function is not an example of single row function?
a) LOWER()
b) MID()
c) DAY()
d) MIN()

2 ______________ command is used to open database „Stock‟.


a) SELECT stock;
b) USE stock;
c) SHOW stock;
d) SELECT * FROM stock;

3 Write any two SQL functions that will display the day of month of given date.

. Consider the Table STORE given below-


4
ItemNo Item Scode Qty Rate LastBuy
1125 Sharpener Classic 23 60 8 23-01-2019
1263 Ball Pen 0.25 22 85 25 01-02-2018
1452 Gel Pen Premium 21 150 12 03-05-2020
236 Gel Pen Classic 21 250 20 06-07-2020
366 Eraser Small 22 250 6 19-03-2018
321 Ball Pen 0.5 21 110 18 03-11-2019
i) State the command that will give the output as-
Item
Gel Pen Premium
Gel Pen Classic
a) SELECT item FROM STORE WHERE lastbuy LIKE „%2020%‟
b) SELECT item FROM STORE WHERE item LIKE „%Pen%‟
c) SELECT item FROM STORE WHERE YEAR(lastbuy)=2020
d) SELECT item FROM STORE WHERE item LIKE „Gel%‟
Choose the correct option:
i. Both (a) and (b).
ii. Both (b) and (d).
iii. Any of the options (a), (c) and (d)
iv. Only (c)

ii) What will be the output of the following command-


Select item, Scode from store where Qty between 60 and 110 and Rate<20;
a)
Item Scode
Sharpener Classic 23
Ball Pen 0.25 22
Eraser Small 22
Ball Pen 0.5 21
b)
Item Scode
Sharpener Classic 23
Ball Pen 0.25 22
Eraser Small 22
c)
Item Scode
Sharpener Classic 23
Ball Pen 0.5 21

d)
Item Scode
Ball Pen 0.25 22
Eraser Small 22
Ball Pen 0.5 21

Downloaded by Deivanai K CS (vngs.pgt.deivanai@velammal.edu.in)


lOMoARcPSD|34467512

iii) Anay has given the following command to obtain the sum of Qty of different Scode -
Select SUM() from store having group by Scode;
but he is not getting the desired result. Help her by writing the correct command.
a. Select sum(Scode) from store group by Scode;
b. Select Scode, sum(Scode) from store group by Scode;
c. Select Scode, sum(Qty) from store group by Scode ;
d. Select Scode,sum(Qty) group by Scode having store ;

iv) Ritisha wants to display item details whose item code ending with 6. Choose correct
command-
a) Select * from store where itemno like „%6‟;
b) Select * from store where mod(itemno,10)=6;
c) Select * from store where itemno%10=6;
d) Select * from store where itemno//10=6
Choose the correct option:
i. Both (a) and (c)
ii. Both (c) and (d)
iii. Both (b) and (c)
iv. Only (d)

v) Help Shama to write command to display total number of Pens available in store.
a) Select item from store where item like „Pen%‟;
b) Select count(*) from store where item like „%Pen‟;
c) Select sum(Qty) from store where item like „%Pen%‟;
d) Select * from store where item like „%Pen%‟;

. Help Sejal in understanding the difference between the following with example :
(i) Update and Alter command

(ii) CHAR and VARCHAR data type

OR
How is Primary key and Candidate key related? Explain.

. Consider the String st=’ Happy Foggy Morning ‘. Write commands in SQL to:
i) To remove leading and trailing spaces
ii) To find the length of the string st.

5 Shikha writes the following commands with respect to a table book having fields-
Bookid, Bname, Publisher, Price
Command1 : Select Publisher from book;
Command2: Select Distinct Publisher from book;
She gets the output as 6 publisher name for the first command but gets an output as 4
publisher name for the second command.
Explain the output with justification.

6. Consider the integer number x=6 and y = 2. Write commands in SQL to:

i. display x raise to the power y


ii. round off x*y to 1 place before decimal place
OR

Explain the use of UNION operator with example.

7. A relation Transport is given below-


OrderNo DriverName DriverGrade Item TravelDate Destination
10012 Ram Yadav A Television 2019-01-19 Mumbai
10014 Somnath Singh NULL Furniture 2019-01-12 Pune
10016 Mohan Verma B Computer 2019-06-06 Lucknow
10018 Rishi Singh A Refrigerator 2019-04-07 Mumbai
10019 Radhe Mohan NULL Television 2019-05-30 Udaipur

Write SQL command to-


Downloaded by Deivanai K CS (vngs.pgt.deivanai@velammal.edu.in)
lOMoARcPSD|34467512

a) Display destination wise number of drivers available.


b) To display driver name who do not have any grade assigned.
c) To display destination where Television and Computer is transported.

8. Write SQL functions to perform the followings-

a) To display name of day of a date column


b) To display position of the first occurrence of substring in a string
c) To removes trailing spaces in the string/column
d) To display numeric month from the date passed
e) To display the date and time at which the function executes

OR
Consider a table Bank with the following data:
Acc_No CName Bname Amount DateofOpen Tot_Trans
1 Karan Kumar Bank of Baroda 15025 12-Dec-1999 10
2 Avi State Bank 25000 17-Jan-2001 3
3 Tanmay Oriental Bank 8000 19-Feb-2003 15
4 Rohini State Bank 38025 02-Jan-1999 9
5 Tanya Saha UCO Bank 17000 20-Aug-2005 10
6 Aditi Arya Oriental Bank 75000 19-Feb-2005 24

Write SQL queries using SQL functions to perform the following operations:
a) To display name of customers whose amount is ending with 25.
b) To display name and date of open whose account is opened in January 1999.
c) To display name and bank name whose account is opened on 19.
th
d) To display customers name who opened account on 50 day of year.
e) To display details of customers whose total transaction is same as number of
characters in their name.

Downloaded by Deivanai K CS (vngs.pgt.deivanai@velammal.edu.in)

You might also like