Practice Questions for GATE, UGC NET, ISRO, and NIELIT | DBMS and SQL with Solutions
Are you preparing for GATE CSE, NTA UGC NET, ISRO, or NIELIT Computer Science exams? Understanding DBMS and mastering SQL is crucial for scoring high in competitive exams. This article contains carefully selected practice questions on functional dependencies, normalization (3NF and BCNF), relational algebra, and complex SQL queries.
Each question is accompanied by a detailed solution, making this resource perfect for competitive exams like GATE, NTA NET, ISRO, and NIELIT. Practice with these high-quality questions to solidify your understanding of database management systems and boost your exam preparation. Let’s start solving!
Question
Consider a relation R(A, B, C, D, E) with functional dependencies F:
F = {AB → C, C → D, D → B, D → E}
If the number of keys in R is a and number of relation in the 3NF decomposition is b what is the value of (a – b)?
Solution:
R(A, B, C, D, E) Closure of (AB)+ = {A, B, C, D, E} Closure of (AC)+ = {A, B, C, D, E} Closure of (AD)+ = {A, B, C, D, E} All of 3 {AB, AC, AD} are key for R. Functional dependencies {D → E} is not in 3NF R₁(ABCD) R₂(DE) {AB → C} {D → E} C → D D → B All attributes are prime attributes in R₁. Total 2 relations required a = 3, b = 2 3 – 2 = 1
Question
Consider the following relational schema Adjacency (x, y) used to state edges of the directed graph.
Which of the following relational algebra expression results vertices set which forms loop with at least two vertices?
- πx( Adjacency ⋈Y=X₁ ∧ Y₁=X ρX₁,Y₁(Adjacency) )
- πx( Adjacency ⋈Y=Y₁ ∧ X=X₁ ρX₁,Y₁(Adjacency) )
- πx( Adjacency ⋈Y=X₁ ∧ Y₁≠X ρX₁,Y₁(Adjacency) )
- πx( Adjacency ⋈Y≠X₁ ∧ Y₁=X ρX₁,Y₁(Adjacency) )
Solution: (A)
Question
Consider the following relation R(A₁, A₂, A₃, … A₁₅) with {A₁, A₂, … A₆} of relation R are simple candidate keys. The number of possible superkeys in relation R is _______.
Solution:
32256 m simple candidate key forms (2m - 1) superkey m = 6 2m - 1 = 63 Total 15 - 6 = 9 non prime attributes Total superkey = 63 × 29 = 63 × 512 = 32256
Question
Consider the following statements:
- S₁: Not every relation is possible to decompose into 3NF with dependency preserving.
- S₂: An attribute declared as UNIQUE can have NULL as its value.
- S₃: From A → B we can derive AC → BC which further leads to A → BC.
How many of the above statements are correct?
Solution:
S₁: The decomposition of 3NF is always lossless and dependency preserving. S₂: An attribute declared as UNIQUE can have NULL as its value. S₃: A → B AC → BC but it cannot derive A → BC Only S₂ is correct.
Question
Consider a relation R(A, B, C, D, E) with functional dependencies F:
F = {AB → C, C → D, D → B, D → E}
If the number of keys in R is a and the number of relation in the 3NF decomposition is b, what is the value of (a – b) ______.
Solution:
- R(A, B, C, D, E)
- Closure of (AB)+ = {A, B, C, D, E}
- Closure of (AC)+ = {A, B, C, D, E}
- Closure of (AD)+ = {A, B, C, D, E}
All of 3 {AB, AC, AD} are key for R.
Functional dependencies {D → E} is not in 3NF.
Decomposition:
- R1(ABCD)
- R2(DE)
All attributes are prime attributes in R1.
Total relations required = 2.
Answer: a = 3, b = 2 → 3 – 2 = 1
Relational Algebra on Directed Graph
Consider the following relational schema Adjacency (x, y) used to state edges of the directed graph. Which of the following relational algebra expressions results in vertices set which forms a loop with at least two vertices?
Options:
πx (Adjacency ⨝ ρx1,y1 (Adjacency))
where Y=x1 ∧ Y1=Xπx (Adjacency ⨝ ρx1,y1 (Adjacency))
where Y=Y1 ∧ X≠x1πx (Adjacency ⨝ ρx1,y1 (Adjacency))
where Y≠x1 ∧ Y1≠Xπx (Adjacency ⨝ ρx1,y1 (Adjacency))
where Y≠x1 ∧ Y1=X
Correct Answer: Option (A)
Question
Consider the following relation R(A1, A2, A3, … A15) with {A1, A2, …. A6} of relation R being simple candidate keys. The number of possible superkeys in relation R is ______.
Solution:
- m simple candidate key forms (2m – 1) superkeys
- m = 6 → 26 – 1 = 63
- Total attributes: 15 – 6 = 9 non-prime attributes
- Total superkeys = 63 × 29 = 63 × 512 = 32256
Answer: 32256
Normalization Statements
Consider the following statements:
- S1: Not every relation possible to decompose into 3NF with dependency preserving.
- S2: An attribute declared as UNIQUE can have NULL as its value.
- S3: From A → B, we can derive AC → BC which further leads to A → BC.
How many of the above statements are correct ______?
Solution:
- S1: The decomposition of 3NF is always lossless and dependency preserving.
- S2: An attribute declared as UNIQUE can have NULL as its value.
- S3: A → B, AC → BC, but we cannot derive A → BC.
Answer: Only S2 is correct.
Question
Consider the given query on the relation P(r, s) and R(s, t)
Q1: πr(P ∩ (πr(P) × πs(R))) Q2: πr((P × πt(R)) ∩ (πs(P) × R)) Q3: πr(P ⨝ R)
Which of the above query produces same result?
- Q1 and Q2 only
- Q2 and Q2 only
- Q1 and Q3 only
- All of Q1, Q2 and Q3
Correct Answer: D
Solution:
All relational algebra queries give the same result.
Question
Consider the following queries on the relation P(A, B) and Q(R, S):
Query 1: πA(P) − πA(P ⨝ Q) Query 2: Select A FROM P WHERE NOT EXISTS (SELECT * FROM Q WHERE P.A ≤ Q.R) Query 3: Select A FROM P WHERE A ≤ ALL (SELECT R FROM Q)
Which of the above queries gives the same result?
- Query 1 and Query 2
- Query 1 and Query 3
- Query 2 and Query 3
- All of Query 1, Query 2 and Query 3
Correct Answer: A
Solution:
Query 1: Gives result set of A values which are greater than every value of Q.
Query 2: Gives result same as Query 1.
Query 3: Gives result set of A values which are less than or equal to all values of Q.
Question
Consider the following relation with functional dependencies R{A, B, C, D, E, F, G}:
FD’s F = {AB → C, AC → B, AD → E, B → D, BC → A, E → G}
If we decompose the relation R into lossless dependency preserving BCNF then which of the following is not a sub relation?
- R1(A, B, C)
- R2(A, B, D, E)
- R3(E, G)
- Both (b) and (c)
Correct Answer: B
Solution:
R[A, B, C, D, E, F, G]
F = {AB → C, AC → B, AD → E, B → D, BC → A, E → G}
{AC, AB, BC} is keys so AD → E, B → D, E → G is not in BCNF. So decompose relation R:
R1(A, B, C), R2(B → D), R3(E → G), R4(A, D, E), R5(ABF)
So in all options, (A, B, D, E) is not a sub relation.
Question
The order of an internal node in a B+ tree is the maximum number of child pointers a node can have. Suppose that a child pointer takes 10 bytes, the search field value takes 13 bytes, and the record pointer is 12 bytes. The block size is 1024 bytes. What is the order of internal node ______?
Correct Answer: 45
Solution:
Let n be the order of the internal node:
10n + 13(n − 1) ≤ 1024
10n + 13n − 13 ≤ 1024
23n ≤ 1037
n ≤ 45.08
n = 45
Question
Consider a relation R(A, B, C, D) with functional dependencies:
A → B, B → C, C → D
Which of the following decomposition is not lossless?
- R1(A, B), R2(B, C), R3(C, D)
- R1(A, B), R2(A, C), R3(A, D)
- R1(A, D), R2(B, D), R3(C, D)
Solution:
(c) Consider an instance of relation R:
| A | B | C | D | |---|---|---|---| | 3 | 3 | 3 | 3 | | 5 | 3 | 3 | 3 |
The join of decomposed relations R1, R2, and R3 contains some extra tuples, so it is not lossless.
Question
Consider the following relation:
Sailors (sid, sname, rating, age)
Instance of sailors:
| sid | sname | rating | age | |-----|-------|--------|-----| | 1 | X | 11 | 19 | | 2 | A | 4 | 15 | | 8 | X | 7 | 33 | | 10 | C | 5 | 17 | | 12 | Y | 8 | 16 | | 18 | D | 15 | 25 | | 25 | Y | 6 | 21 |
How many number of tuples is returned by the following SQL query when executed on the given instance of Sailors?
Select S.sname FROM Sailors S WHERE NOT EXISTS ( SELECT * FROM Sailors S1 WHERE S1.age < 18 AND S.rating <= S1.rating );
- 1
- 2
- 3
- 4
Solution:
SQL query returns the sname of sailors with a higher rating than all sailors with age less than 18. The relation returned by the SQL query:
| sname | |-------| | X | | Y | | D |
Correct Option: 3 tuples are returned.
Tag:3NF Decomposition, B+ Tree Order, BCNF Decomposition, Database Design Questions, Database Indexing, Database Management System, DBMS 3NF, DBMS BCNF, DBMS Concepts, DBMS Exam Questions, DBMS for ISRO, DBMS for NTA NET, DBMS GATE Practice, DBMS GATE Practice Set, DBMS GATE Questions, DBMS MCQs, Directed Graphs in DBMS, Functional Dependencies, Functional Dependencies in DBMS, Functional Dependency in GATE, GATE CSE, GATE Database Questions, ISRO Computer Science, ISRO Computer Science Questions, Lossless Decomposition, NIELIT DBMS, Normalization Practice, Normalization Questions, NTA UGC NET, relational algebra, Relational Algebra Problems, Relational Schema Problems, Relational Schema Questions, SQL and DBMS, SQL and DBMS Solutions., SQL for Competitive Exams, SQL Joins, SQL MCQs, SQL Optimization Questions, SQL Practice Questions, SQL Practice Sets, SQL Queries, SQL Queries Practice, SQL Query Optimization, SQL Questions for Competitive Exams, SQL Solutions, SQL with Solutions, Superkeys, Superkeys and Candidate Keys