Xii Ip Support Material
Xii Ip Support Material
CLASS – XII
SUBJECT – INFORMATICS PRACTICES
SUPPORT MATERIAL
SQL – STRUCTURED QUERY LANGUAGE
Question Bank
[1 mark questions] Q.NO. 1-21
1) The avg( ) function in MySQL is an example of ………………….
(i) Math Function
(ii) Text Function
(iii) Date Function
(iv) Aggregate Function
Ans:- (v) Aggregate Function
2) The …………. Command can be used to make changes in the rows of table in
SQL.
Ans:- UPDATE
3) The SQL Command that will display the current time and date.
Ans :- Select now();
4) The mid()function in MySql is an example of .
a. Math function
b. Text function
c. Date Function
d. Aggregate Function
Ans:- b. 15.9
18)
Manish wants to select all the records from a table named “Students”
where the value of the column “FirstName” ends with an “a”. Which of
the following SQL statement will do this?
a. SELECT * FROM Students WHERE FirstName = ‘a’;
b. SELECT * FROM Students WHERE FirstName LIKE ‘a%’;
c. SELECT * FROM Students WHERE FirstName LIKE ‘%a’;
d. SELECT * FROM Students WHERE FirstName = ‘%a%’;
Ans:-
d. SELECT * FROM Students WHERE FirstName = ‘%a%’;
19) The command can be used to add a new column to the table.
Ans:- ALTER
20) Which SQL command is used to describe the structure of the table ?
Ans:- DESC
21) Foreign Key in a table is used to enforce
i) Data dependency
ii) Referential Integrity
iii) Views
iv) Index Locations
Ans:- ii) Referential Integrity
22) A table ‘Student’ contains 5 rows and 4 columns initially. 2 more rows are
added and 1 more column is added . What will be the degree and
cardinality of the table student after adding these rows and columns?
i) 7, 5
ii) 5,7
iii) 5,5
iv) None of the above
Ans:- ii) 5,7
23) Insert into student values(1,’ABC’,’10 Hari Nagar’) is a type of which
command :
i) DML
ii) DDL
iii) TCL
iv) DCL
Ans:- i) DML
24) What will be the output of - select mid('Pyhton Programming’,3,9);
i) ton Progr
ii) ton Progr
iii) hton Prog
iv) htonProg
Ans:- iii) hton Prog
25) Write the output of the following SQL statement:
SELECT TRUNCATE(15.79,-1) , TRUNCATE(15.79,0),
TRUNCATE(15.79,1);
a. 15 15 15.7
b. 10 15.7 15.9
c. 10 15 15.7
d. 10 10 15.9
Ans:- c. 10 15 15.7
26) The COUNT( ) in MySQL is an example of :
a. Math function
b. Text function
c. Date Function
d. Aggregate Function
Ans:- d. Aggregate Funcion
27) …….. which of the following sublanguages of SQL is used to query
information from the database and to insert tuples into, delete tuples
from and modify tuples in the database?
a. DML
b. DDL
c. Query
d. Relational Schema
Ans:- a. DML
28) The ……… clause of SELECT query allows us to select only those rows in
the result that satisfied a specified condition.
a. WHERE
b. FROM
c. HAVING
d. LIKE
Ans:- a. WHERE
29)
Write the output of the following SQL command.
select substr(“COMPUTER”,3,4);
a. MPUT
b. PUTE
c. PU
d. MP
Ans: - a. MPUT
30)
The now() function in MySql is an example of ___________________.
a. Math function
b. Text function
c. Date Function
d. Aggregate Function
Ans :- c. Date Function
31) The _________ command is used to make the changes in a table
permanent.
Ans:- COMMIT
32) Give SQL command that will display the current month from the date
and time.
Ans :- MONTH( )
33) Which of the following keywords will you use in the following query to
display all the records of students whose name start with S?
SELECT * from student where name “S%”
Ans :- LIKE
34) Which of the following is an aggregate function:
a. Upper()
b. Trim()
c. Date()
d. Sum()
Ans:- d. SUM()
35) Write the output of the following SQL
command:
SELECT left(“Jammu Region”, 5);
a. Region
b. Jammu
c. Jammu Region
d. None of the above.
Ans:- b. Jammu
36)
What will be the output of the following code?
SELECT MOD(14,3);
Ans: 2
37)
What will be the result of the following query based on the table given
here.
SELECT COUNT(Salary) FROM Instructor;
Ans:- COUNT(Salary)
--------------------
5
38) Write the command to delete all the data of the table ‘activity’ retaining
only structure.
Ans:- DELETE FROM ACTIVITY;
39) Write the output for the following SQL commands
Select round(15.193 , -1);
Ans:- 10
40) Write a SQL query to display date after 20 days of current date on your
system.
Ans:- SELECT CURDATE( ) + 10;
41) Write the output for the following sql command
Select SUBSTR(‘ABCDEFG’, -5 ,3)
Ans:- CDE
42) Which keyword is used to arrange the result of order by clause in
descending order?
a. DSEC
b. DES
c. DESC
d. DESNO
Ans: C. DESC
43) Write the output of the following SQL command.
Select round(14.872,1)
a)14.87
b)14.9
c)14.8
d) 15
Ans:- b) 14.9
44) The command can be used to change the size of column to the
table.
Ans:- ALTER
45) The command can be used to makes changes in the
rows of a table in SQL.
Ans:- Update
46) Write the output of the following SQL command.
select round (49.88);
a. 49.88
b. 49.8
c. 49.0
d. 50
Ans:- d. 50
47) Write the output of the following SQL command.
select round (19.88,1);
a. 19.88 b. 19.8 c. 19.9 d. 20.0
Ans:- c. 19.9
48) Select count(*) from Employee;
The above query will not consider the following:
a) Numeric value b) Text value c) Null value d) Date
value
Ans:- c) NULL Value
49) Which of the following is/are not correct aggregate functions in SQL:
a. AVG() b) COUNT() c) TOTAL() d) MAX()
Ans:- c) Total( )
50) The command can be used to make changes in the definition of a
table in SQL.
Ans:- ALTER
51) Write the SQL clause used to sort the records of a table.
Ans:- ORDER BY
52) Write the output of the following SQL command.
select round(15.857,-1);
a. 15.8
b. 15.9
c. 15.0
d. 20
Ans:- 20
53) The now()function in MySql is an example of .
a. Math function
b. Text function
c. Date Function
d. Aggregate Function
Ans:- c. Date Function
54) The command can be used to makes changes in the
structure of a table in SQL.
Ans:- ALTER
55) Write the SQL command that will display the time and date at which
the
command got executed.
Ans: SELECT NOW();
56) In SQL NULL value means :
(i) 0 value (ii) 1 value (iii) None value (iv) None of the
above
Ans:- iii) None value
57) Find the output of SQL Query:-
SELECT MOD(11, 3);
Ans:- 2
58) The MAX() function in MySql is an example of
___________________.
a. Math function
b. Text function
c. Date Function
d. Aggregate Function
Ans:- d. Aggregate Function
59) Write the output of the following SQL command.
select round(314.82,-1);
a. 314.0 b. 310.0 c. 314.8 d. 300.0
Ans:- d. 300
60) What will be the output of the following SQL command:
SELECT LTRIM(“ RAJKUMAR “);
Ans:- “RAJKUMAR “
(Removes spaces from left side)
61) Write the output of the following SQL command.
select pow(2.37,3.45);
a. 17.62
b. 19.62
c. 18.35
d. 15.82
Ans:- b. 19.62
62) Having clause is used with ____________________________function.
a. Math function
b. Text function
c. Date Function
d. Aggregate Function
Ans:- Aggregate Function
63) Write the output of the query:
select instr('Toolbarbar','bar');
Ans:- 5
64) alter() function in MySql is part of ___________________
a. DDL command
b. DML Command
c. TCL command
1) State any two differences between single row functions and multiple row functions.
OR
What is the difference between the order by and group by clause when used along with the select
statement. Explain with an example.
Ans:- Differences between single row functions and multiple row functions. (i) Single row functions work on
one row only whereas multiple row functions group rows (ii) Single row functions return one output
per row whereas multiple row functions return only one output for a specified group of rows.
OR The order by clause is used to show the contents of a table/relation in a sorted manner with
respect to the column mentioned after the order by clause. The contents of the column can be
arranged in ascending or descending order.
The group by clause is used to group rows in a given column and then apply an aggregate function eg
max(), min() etc on the entire group. (any other relevant answer)
Single row v/s Multiple row functions 1 mark for each valid point
Group by v/s Order by 1 mark for correct explanation 1 mark for appropriate example
2) Consider the decimal number x with value 8459.2654. Write commands in SQL to: i. round it off to a
whole number ii. round it to 2 places before the decimal.
She gets the output as 4 for the first command but gets an output 3 for the second command.
Explain the output with justification.
Ans:- This is because the column commission contains a NULL value and the aggregate functions do not
take into account NULL values. Thus Command1 returns the total number of records in the table
whereas Command2 returns the total number of non NULL values in the column commission.
4) Consider the following SQL string: “Preoccupied”
a. “occupied” b. “cup”
OR
a. the position of the substring ‘cup’ in the string “Preoccupied” b. the first 4 letters of the string
OR
OR
UPDATE command is a part of DML command and used to update the data of rows of a table.
While ALTER command is a part of DDL command and used to change the structure of a table like
adding column, removing it or modifying the datatype of columns.
Eg: UPDATE EMP SET SALARY = 20000;
Ans:- This is because the column DESTINATION contains a NULL value and the aggregate functions do not
take into account NULL values. Thus Command1 returns the total number of records in the table
whereas Command2 returns the total number of non NULL values in the column DESTINATION.
8) Write the output for following queries:
i. select MOD(11,4) "Modulus", power(3,2) "Raised";
ii. select CURDATE( )+10;
OR
i. select length('CORONA COVID-19');
ii. select lcase('COMputer Science');
or
i. 15
ii. ‘computer science’
9) Consider the decimal number x with value 7459.3654. Write commands in SQL
to:
i) round it off to a whole number
ii) round it to 2 places before the decimal.
10) Shailly writes the following commands with respect to a table Employee
having fields, empno, name, department, commission.
Command1 : SELECT COUNT(*) FROM EMPLOYEE;
Command2 : SELECT COUNT(COMMISSION) FROM EMPLOYEE;
She gets the output as 7 for the first command but gets an output 5 for the
second command. Explain the output with justification.
Ans:- This is because the column commission contains a NULL value and the aggregate
functions do not take into account NULL values. Thus Command1 returns the total
number of records in the table whereas Command2 returns the total number of non
NULL values in the column commission.
OR
OR
(student may use other functions like – substring/ mid/ right .. etc
12) State any two differences between Update and alter commands.
OR
What is datatype? What are the main objectives of datatypes?
Ans:- Data types are mean to identify the type of data and its associated functions.
The main objectives of datatypes is to clarify the type of data a variable can store and which
operations can be performed on it.
13) Consider the decimal number n with value 278.6975. Write commands in SQL :
i. That gives output 279
ii. That gives output 280
But the Query is not executing successfully. What do you suggest to him in order to execute this
query i.e. write the correct query.
(ii) Write a SQL query to display the details of those employees whose Salary column has some
values.
OR
a. select instr("Master Planner","Plan");
b. select right("Master Planner",4); or some other queries that produces same results.
20) Consider the following SQL string: “Mental Toughness Helps You Succeed”
Write commands to display following using functions:
a. “Toughness”
b. “Succeed”
OR
Considering the same string: “Mental Toughness Helps You Succeed”
Write SQL commands to display:
a. the position of the substring ‘’Helps’ in the string “Mental Toughness Helps You Succeed”
the first 6 letters of the string
Ans:- i) Select mid(‘Mental Toughness Helps You Succeed’, 8, 9)
ii) Select right(‘Mental Toughness Helps You Succeed’, 7);
OR
i) select instr("Mental Toughness Helps You Succeed",’Helps’);
ii) select left("Mental Toughness Helps You Succeed",6);
1 Mark each for correct function usage
21) Find out the error in the following SQL command and correct the same.
Select * from employee group by dept where sum(salary) > 2000000
Ans:- Select * from employee group by dept where sum(salary) > 2000000 in this query in place of WHERE
clause HAVING clause to be used.
22) Helps Abhay to Compare Having clause and Order by clause?
Or
Shewani has recently started working in MySQL. Help her in understanding the
difference between where and having clause.
Ans:- Having clause is used in conjunction with group by clause in MySQL. It is used to provide
condition based on grouped data. On the other hand, order by clause is an independent
clause used to arrange records of a table in either ascending or descending order on the
basis of one or more columns
OR
COUNT(*) returns the number of items in a group, including NULL values and
duplicates. COUNT(expression) evaluates expression for each row in a group and
returns the number of non null values
2 marks of correct explanation & for any other relevant answer.
23) Write commands in SQL to:
i. round off value 56789.8790 to nearest thousand’s place.
ii. Display day from date 13-Apr-2020.
Ans:- i. Select ROUND(56789.8790,-3);
ii. Select DAY(‘2020-04-13’) 1 mark each for correct answer.
24) Given Table Course:
Ans:- Primary Key : A column of collection of columns to identify a tuple in a relation. It is used to
search / locate row in a relation. There can be only one primary key in a table. 1 mark for
correct definition with proper significance.
1 mark for stating only one primary key in a table.
OR
TRIM () function is used to remove leading and trailing spaces from a string a table. It can be
used as
TRIM(String)
For example;
SELECT TRIM(' bar ');
-> 'bar'
1 mark for stating purpose of the functions 1 mark for correct example.
27)
Consider the following ‘Student’ table.
(i) What will be the most suitable datatype for the grade column and why?
(ii) Write a command to insert Suman’s record with the data as shown in the table.
Ans:- (i) Gender column datatype char(1) as all the possible values can be accommodated and it
will be space efficient.
(ii) INSERT INTO Student (Rollno, Sname, Subject, Marks) VALUES (“003”, ”SUMAN”,
“IP”, 75);
1 mark for each correct answer
28) Explain the working of ORDER BY clause of SELECT query with proper example.
Ans:- The ORDER BY keyword is used to sort the result-set in ascending or descending order.
The ORDER BY keyword sorts the records in ascending order by default. To sort the records in
descending order, use the DESC keyword.
1 mark for correct explanation. 1 mark for appropriate example
29)
Consider a string “AS YOU know MORE” 2
Write the queries for the following tasks.
(i) Write a command to display “know”.
(ii) Write a command to display number of characters in the string.
OR
Consider a string “You Grow more” stored in a column
str. What will be the output of the following queries?
(i) SELECT UPPER(str);
(ii) SELECT substr(str,-9,4);
Ans:- a. select Type, avg(Price) from Vehicle group by Type having Qty>20;
b. select Company, count(distinct Type) from Vehicle group by Company;
c. Select Type, sum(Price* Qty) from Vehicle group by Type;
a. ½ mark for the Select with avg(), ½ mark for the having clause
b. ½ mark for the Select with count() , ½ mark for group by clause
c. ½ mark for the Select with sum() , ½ mark for the group by clause
2) Consider the table Garment and write the query:
Ans:- (i) select area, count(sname) as “Number of salesman” from Salesman group by area;
(ii) select monthname(dateofjoin) from Salesman where area=’Ajmer’;
(iii) select sum(salary) from Salesman;
6)
TABLE NAME : PHARMADB
Ans:-
a. Select sum(price) from pharmadb group by pharmacyname having count(*)>1;
b. Select PharmacyName from Pharmadb order by DrugID;
a. Rx Pharmacy 2 Raj
Medicos 1
MyChemist 2
a. ½ mark for the Select with sum(), ½ mark for the having clause
b. ½ mark for the Select ,½ mark for the order by clause
1 marks for correct output.
7)
Consider a MySQL table ‘product’ 3
P_ID PROD_NAME PROD_PRICE PROD_QTY
P01 Notebook 85 500
P02 Pencil Box 76 200
P03 Water Bottle 129 50
P04 School Bag 739 70
(i) Display maximum PROD_QTY.
(ii) Display the value of each product where the value of each product is calculated as
PROD_PRICE * PROD_QTY
(iii) Display average PROD_PRICE.
OR
Write SQL queries using SQL functions to perform the following operations:
a) Display salesman name and bonus after rounding off to zero decimal places.
b) Display the position of occurrence of the string “ta” in salesman names.
c) Display the four characters from salesman name starting from second character.
d) Display the month name for the date of join of salesman
e) Display the name of the weekday for the date of join of salesman
Ans:- i) monthname(date(now()))
ii) trim(“ Panaroma “)
iii) dayname(date(dob))
iv) instr(name, fname)
v) mod(n1,n2)
1 mark for each correct answer
OR
Write SQL queries using SQL functions to perform the following operations:
a) Convert all the names into lower case.
b) Display the position of occurrence of the string “sh” in Name.
c) Display the four characters from Department starting from second character.
d) Display the month name for the date of admission.
e) Display the name of the weekday for the date of admission.
OR
Write the SQL functions which will perform the following operations:
i) To display the day of month of current date.
ii) To remove spaces from the beginning and end of a string, “ Informatics
Practices “.
iii) To display the name of the day eg. Friday or Sunday from your date of birth, dob.
iv) To convert your name into Upper case.
v) To compute the mode of two numbers num1 and num2.
OR
i. SELECT DAYOFMONT(CURDATE());
ii. SELECT TRIM(“ Informatics Practices “;
iii. SELECT DAYNAME(“2015-07-27”);
iv. SELECT UPPER(Name);
v. SELECT MOD(num1,num2);
3) Write the SQL functions which will perform the following operations:
i) To display the name of the month of the current date.
ii) To remove spaces from the beginning and end of a string, “ KV Sangathan “.
iii) To display the name of the day eg, Friday or Sunday from your date of birth, dob.
iv) To print the value of square root of 2 upto 2 decimal points.
v) To compute the remainder of division between two numbers, n1 and n2
OR
Write SQL for question from (i) to (iv) and output for SQL queries (v) and (vi),
which are based on the table: KV given below:
(i) Print the details of KVs whose StationCode between 300 and 500
(ii) Print the details of KVs whose name ends with AFS
(iii) Print the details of KVs of Jaipur region
(iv) Print the number of KVs Zone-wise
(v) Select Region, count(KVName) from KV where Zone=’West’ group by Region
(vi) Select * from KV where substr(KVName, 2, 3)=’and’ or StationCode=390;
OR
OR
Consider the following table Garments. Write SQL commands for the following statements.
Table : Garments
GCode GName Price MCode Launch_Date
10001 Formal Shirt 1250 M001 2008-12-12
10020 Frock 750 M004 2007-09-07
10007 Formal Pant 1450 M001 2008-03-09
10024 Denim Pant 1400 M003 2007-04-07
10090 T-Shirt 800 M002 2009-05-12
OR
a) Display shop name and bonus after rounding off to zero decimal places.
b) Display the position of occurrence of the string “tech” in shop names.
c) Display three characters from shop name starting from second character.
d) Display the month name for the date of opening of shop
e) Display the name of the shop in all capitals.
Write SQL queries using SQL functions to perform the following operations:
a) Display company name and body wheel base after rounding off to nearest ten’s
decimalplaces.
b) Display the position of occurrence of the string “dan” in body style.
c) Display the 3 characters from company name starting from second character.
d) Display the year of manufacturing for sedan;
e) Display the name of the weekday for the manufacturing date.
Ans:- a) Select company, round(wheel-base,-1) from automobile;
b) Select instr(body-style,’dan’) from automobile;
c) Select substr(company,2,3) from automobile; /mid(company,2,3)
d) Select year(dateofmanufacture) from automobile where body-style=’sedan’;
e) Select dayname(dateofmanufacture) from automobile;