1
Branch : CSE & IT Batch : Hinglish
Database Management System
Query Language DPP 02
[MCQ] [MSQ]
1. Consider the following keywords. 3. Consider the following product relation
A. SELECT Products (PID,PName, Cost)
B. TOP
Assume that PID is a primary key of relation. Which
C. DISTINCT
SELECT statement should we used to limit the display
D. FROM
of product information to the product having price/cost
E. WHERE
F. GROUP BY less than 50?
G. HAVING H. ORDER BY (a) SELECT PID, PName FROM Products WHERE
The above keywords are used in the given SQL query Cost < 50;
below. (b) SELECT PID, PName FROM Products WHERE
SLECT TOP NumberOfRows DISTINCT Col1, Col2 Cost< = 50;
FROM TableNameX, TableNameY
(c) SELECT PID, PName FROM Products WHERE
GROUP BY ColumnName
PID IN (SELECT PID FROM Products WHERE
HAVING expression
Cost <50);
ORDER BY ColumnName;
Which of the following is the correct query execution (d) SELECT PID, PName FROM Products GROUP
order according to SQL Standard? BY PID Having Cost < 50;
(a) D E F G A H B C
(b) D E F G A C H B [MCQ]
(c) D E F G A B C H 4. The Employees table contains these columns
(d) A D E F G H C B empID NUMBERS (4)
LastName VARCHAR (25)
[MSQ]
JobID VARCHAR (10)
2. Consider the following employee table
Suppose that, you want to search for string that contains
Employees (EMPID, EmpName, Sal, DeptID,
ManagerID) assume that EMPID is primary key of ‘Negi’ in the LastName column which SQL statement
relation. which of the following SELECT statements will be used?
is/are invalid? (a) SELECT empID, LastName, JobID FROM
(a) SELECT ManagerID, DeptID FROM employees; employees WHERE LastName LIKE ‘%Negi’;
(b) SELECT ManagerID, DISTINCT DeptID FROM (b) SELECT empID, lastName, JobID FROM
employees;
employees WHERE LastName = ‘Negi_%’;
(c) SELECT DISTINCT ManagerID, DISTINCT
(c) SELECT empID, lastName, JobID FROM
DeptID FROM employees;
employees WHERE LastName LIKE ‘Negi’;
(d) SELECT DISTINCT ManagerID, DeptID FROM
employees; (d) None of these
2
[NAT] [MCQ]
5. Consider a relation A(P,Q) currently has tuples {(1, 2), 8. Consider the following statements.
(1, 3), (3, 4) } and relation B(Q, R) currently has {(2, S1: A DELETE statement can remove rows based on
5), (4, 6), (7, 8)}. Then the number of tuples in the a single condition on a table
result of the SQL query: SELECT * FROM A S2: An INSERT statement can add a single row based
NATURAL OUTER JOIN B; is ? on multiple condition on a table.
Choose the correct statements
[MSQ] (a) Only S1 is true
6. Which of the following statement is/are true about (b) Only S2 is true
constraints? (c) Both S1 and S2 are true
(a) The constraints is applied only to INSERT (d) Both S1 and S2 are false
operation into table. [MSQ]
(b) A foreign key can’t contain NULL values. 9. Which of the below statement are true regarding the
(c) A column with the unique constraint can store WHERE and HAVING clause in a SQL statement?
(a) WHERE and HAVHIG clause can’t be used
NULLS.
together in SQL Statement.
(d) We can have more than one column in a table as a (b) The HAVING clause condition can have
part of primary key. aggregate function.
(c) The WHERE clause is used to exclude rows
[MCQ] before the grouping of data.
(d) The HAVING clause is used to exclude one or
7. Consider the following statements
more aggregated results after grouping data.
S 1: An INSERT statement can add multiple rows per
execution to a table. [MCQ]
S 2: An UPDATE Statement can modify multiple rows 10. Given the database schema A(P,Q,R) which of the
based on multiple condition on a table. following SQL query can be used to test whether the
Choose the correct statements. functional dependency PR holds on relation A?
(a) Only S1 is true (a) Select P from A group by P having count (distinct
R) >1
(b) Only S2 is true
(b) Selects P from A group by A having count
(c) Both S1 is S2 are true
(distinct R) >1
(d) Both S1 and S2 are false (c) Select R from A group by P having count (distinct
R) >1
(d) None of the above
3
Answer Key
1. (b) 6. (c, d)
2. (b, c) 7. (c)
3. (a, c) 8. (c)
4. (c) 9. (b, c, d)
5. (4) 10. (a)
4
Hints & Solutions
1. (b) Option (b):
The correct query execution order. The following SQL selects all Lastname starting with
FROM D "Negi".
WHERE E Option (c):
GROUP BY F The following SQL selects all Lastname contains with
HAVING G "Negi".
SELECT A Or
The equivalent SQL query:
DISTINCT C
SELECT empID, lastName, JobID FROM employees
ORDER BY H
WHERE LastName LIKE ‘%Negi%’;
TOP B
So, correct order of execution is DEFGACHB i.e…
5. (4)
option (b).
A B A⋈B
2. (b, c) P Q Q R P Q R
Option b & c are having invalid SELECT statement, 1 2 2 5 1 2 5
1 3 4 6 3 4 6
because we cannot apply DISTINCT keyword on 3 4 7 8 1 3 -
attribute basis, DISTINCT keyword chooses a distinct - 7 8
row. Therefore the number of tuples in the results are 4.
3. (a & c) 6. (c, d)
Option (a) is correct because this SQL statement (a) False; we can also apply for an update operation
displays the product information of product with cost into table.
less than 50. (b) False; A foreign key can contain NULL values as
Option (b) is incorrect because it will return product well
(c) True; A column with the UNIQUE constraint can
information of product with cost equal to 50.
store NULL values but not duplicate value.
Option (c) is correct SQL statement because in this we
(d) True; a primary key can also be a composite key.
used nested SQL query.
First, we find PID of product whose cost is less than 50,
7. (c)
and then we compare PID with the result of inner
S1: True; An INSERT statement can add multiple,
query.
rows per execution to a table by using the
Option (d) is incorrect SQL statement because it cannot following SQL query.
select non aggregate column PName in SELECT INSERT INTO table 2 (col1, col2, col3, ….)
clause. SELECT col1, col2, col3,…
S2: True; An UPDATE statement can modify
4. (c) multiple rows based on multiple conditions on
The LIKE command is used in a WHERE clause to table.
search for a specified pattern in a column.
You can use two wildcards with LIKE: 8. (c)
• % Represents zero, one, or multiple characters S1: True; DELETE statement can remove rows based
• _ -Represents a single character no/single/multiple condition on a table.
Option (a) S2: True; An insert statement can add a single row
The following SQL selects all Lastname ending with based on multiple conditions on a table.
"Negi".
5
9. (b, c, d) (c) True; WHERE clause is used to exclude rows
(a) False; A query can have both WHERE and before the grouping of data.
HAVING clauses.
(b) True; The HAVING clause condition can have (d) True; The HAVING clause is used to exclude
aggregate function. aggregated results after grouping data.
10. (a)
If the query in option a returns non null output, then the
dependency does not hold. Hence (a) option is correct.
Any issue with DPP, please report by clicking here:- https://forms.gle/t2SzQVvQcs638c4r5
For more questions, kindly visit the library section: Link for web: https://smart.link/sdfez8ejd80if
PW Mobile APP: https://smart.link/7wwosivoicgd4