50 DBMS MCQs with Answers
Question 1 |
it is on a set of fields that form a candidate key. | |
it is on a set of fields that include the primary key. | |
the data records of the file are organized in the same order as the data entries of the index. | |
the data records of the file are organized not in the same order as the data entries of the index. |
Discuss it
Question 2 |
3 | |
4 | |
5 | |
6 |
Discuss it
Question 3 |
P and R | |
P and S | |
Q and R | |
Q and S |
Discuss it
CREATE TABLE temp
(
id INT,
name VARCHAR(100)
);
INSERT INTO temp VALUES (1, "abc");
INSERT INTO temp VALUES (2, "abc");
INSERT INTO temp VALUES (3, "bcd");
INSERT INTO temp VALUES (4, "cde");
SELECT Count(*)
FROM temp
GROUP BY name;
Output:count(*) -------- 2 1 1Alternative way - Statement (P) "An SQL query can contain a HAVING clause even if it does not have a GROUP BY clause" is correct because Having caluse is applied after the aggregation phase and must be used if you want to filter aggregate results and Having doesn't require Group By clause. A HAVING clause without a GROUP BY clause is valid and (arguably) useful syntax in Standard SQL. Consider this example, which is valid Standard SQL:
SELECT 'T' AS result FROM Book HAVING MIN(NumberOfPages) < MAX(NumberOfPages);Statement (S) "Not all attributes used in the GROUP BY clause need to appear in the SELECT clause" is correct but if we use Group By clause must, there are limitations on what we can put into the Select clause.
Question 4 |
T1: read (P) ;
read (Q) ;
if P = 0 then Q : = Q + 1 ;
write (Q) ;
T2: read (Q) ;
read (P) ;
if Q = 0 then P : = P + 1 ;
write (P) ;Any non-serial interleaving of T1 and T2 for concurrent execution leads toA serializable schedule | |
A schedule that is not conflict serializable | |
A conflict serializable schedule | |
A schedule for which a precedence graph cannot be drawn |
Discuss it
Question 5 |
Table A Id Name Age ---------------- 12 Arun 60 15 Shreya 24 99 Rohit 11 Table B Id Name Age ---------------- 15 Shreya 24 25 Hari 40 98 Rohit 20 99 Rohit 11 Table C Id Phone Area ----------------- 10 2200 02 99 2100 01Consider the above tables A, B and C. How many tuples does the result of the following SQL query contains?
SELECT A.id
FROM A
WHERE A.age > ALL (SELECT B.age
FROM B
WHERE B. name = "arun")
4 | |
3 | |
0 | |
1 |
Discuss it
Question 6 |
Borrower Bank_Manager Loan_Amount Ramesh Sunderajan 10000.00 Suresh Ramgopal 5000.00 Mahesh Sunderajan 7000.00What is the output of the following SQL query?
SELECT Count(*)
FROM ( ( SELECT Borrower, Bank_Manager
FROM Loan_Records) AS S
NATURAL JOIN ( SELECT Bank_Manager, Loan_Amount
FROM Loan_Records) AS T );3 | |
9 | |
5 | |
6 |
Discuss it
See Question 3 of http://www.geeksforgeeks.org/database-management-systems-set-4/
Question 7 |
I only | |
II only | |
Both I and II | |
Neither I nor II |
Discuss it
2 Phase Locking (2PL) is a concurrency control method that guarantees serializability. The protocol utilizes locks, applied by a transaction to data, which may block (interpreted as signals to stop) other transactions from accessing the same data during the transaction’s life. 2PL may be lead to deadlocks that result from the mutual blocking of two or more transactions. See the following situation, neither T3 nor T4 can make progress.
Timestamp-based concurrency control algorithm is a non-lock concurrency control method. In Timestamp based method, deadlock cannot occur as no transaction ever waits.
Question 8 |
Consider the following relational schema:
Suppliers(sid:integer, sname:string, city:string, street:string) Parts(pid:integer, pname:string, color:string) Catalog(sid:integer, pid:integer, cost:real)
Consider the following relational query on the above database:
SELECT S.sname
FROM Suppliers S
WHERE S.sid NOT IN (SELECT C.sid
FROM Catalog C
WHERE C.pid NOT IN (SELECT P.pid
FROM Parts P
WHERE P.color<> 'blue'))
Assume that relations corresponding to the above schema are not empty. Which one of the following is the correct interpretation of the above query?
Find the names of all suppliers who have supplied a non-blue part. | |
Find the names of all suppliers who have not supplied a non-blue part. | |
Find the names of all suppliers who have supplied only blue parts. | |
Find the names of all suppliers who have not supplied only blue parts. | |
None |
Discuss it
(D) option matched because given query returns suppliers who have not supplied any blue parts. That means it can include other than blue parts.
(A): False, as this may include blue parts and may not include "null" parts.
(B): Obviously false because it returning other than any blue part.
(C): Obviously false because it does not return this.
(D): Correct. Please try here: http://sqlfiddle.com/#!9/9ae12d/1/0
This explanation is contributed by Archit Garg.
Question 9 |
non-key and ordering | |
non-key and non-ordering | |
key and ordering | |
key and non-ordering |
Discuss it
For example: A small database file storing roll no and subjects enrolled for a particular student. Here data can be grouped on the basis of Roll No.s.
Hence to create such kind of index files, fields could be non-key attributes and which are in ordered form so as to form clusters easily.
Hence option (A) – non key and ordering.
Additional points for Clustered Indexing:
1. The number of entries in the index file are the unique values of the attribute on which indexing is done.
2. The pointer in the index file will give the base address of the block in which the value appear for the first time.
http://quiz.geeksforgeeks.org/indexing-in-databases-set-1/
This solution is contributed by Yashika Arora.Question 10 |
S1: A foreign key declaration can always
be replaced by an equivalent check
assertion in SQL.
S2: Given the table R(a,b,c) where a and
b together form the primary key, the
following is a valid table definition.
CREATE TABLE S (
a INTEGER,
d INTEGER,
e INTEGER,
PRIMARY KEY (d),
FOREIGN KEY (a) references R) Which one of the following statements is CORRECT?S1 is TRUE and S2 is FALSE. | |
Both S1 and S2 are TRUE. | |
S1 is FALSE and S2 is TRUE. | |
Both S1 and S2 are FALSE. |
Discuss it
Using a check condition we can have the same effect as Foreign key while adding elements to the child table. But when we delete an element from the parent table the referential integrity constraint is no longer valid. So, a check constraint cannot replace a foreign key.
So, we cannot replace it with a single check.
S2: Given the table R(a,b,c) where a and
b together form the primary key, the
following is a valid table definition.
CREATE TABLE S (
a INTEGER,
d INTEGER,
e INTEGER,
PRIMARY KEY (d),
FOREIGN KEY (a) references R)
False:
Foreign key in one table should uniquely identifies a row of other table. In above table definition, table S has a foreign key that refers to field 'a' of R. The field 'a' in table S doesn't uniquely identify a row in table R.


.png)