DBMS GATE PYQ – 50 MCQs from GATE CSE Previous Year Questions
Q1: Suppose a database system crashes again while recovering from a previous crash. Assume checkpointing is not done by the database either during the transactions or during recovery. Which of the following statements is/are correct?
i. All the transactions that are already undone and redone will not be recovered again. ii. The same undo and redo list will be used while recovering again. iii. The database will become inconsistent. iv. The system cannot recover any further.
Q2: A relation r(A, B) in a relational database has 1200 tuples. The attribute A has integer values ranging from 6 to 20, and the attribute B has integer values ranging from 1 to 20. Assume that the attributes A and B are independently distributed.
Q3: The following relation records the age of 500 employees of a company, where empNo (indicating the employee number) is the key: Consider the following relational algebra expression: What does the above expression generate?
i. Employee numbers of only those employees whose age is more than the age of exactly one other employee ii. Employee numbers of all employees whose age is not the minimum. iii. Employee numbers of all employees whose age is the minimum. iv. Employee numbers of only those employees whose age is the maximum.
Q4: Let r i(z) and w i(z) denote read and write operations respectively on a data item z by a transaction T i. Consider the following two schedules. S1: r 1(x) r 1(y) r 2(x) r 2(y) w 2(y) w 1(x) S2: r 1(x) r 2(x) r 2(y) w 2(y) r 1(y) w 1(x) Which one of the following options is correct?
i. Both S1 and S2 are conflict serializable. ii. Neither S1 nor S2 is conflict serializable. iii. S1 is conflict serializable, and S2 is not conflict serializable. iv. S1 is not conflict serializable, and S2 is conflict serializable.
Q5: Consider the relation R(P, Q, S, T, X, Y, Z, W) with the following functional dependencies Consider the decomposition of the relation R into the consistent relations according to the following two decomposition schemes. D1: R=[(P,Q,S,T); (P,T,X); (Q,Y); (Y,Z,W)] D2: R=[(P,Q,S);(T,X);(Q,Y);(Y,Z,W)] Which one of the following options is correct?
i. Both D1 and D2are lossy decompositions. ii. D1 is a lossless decomposition, but D2 is a lossy decomposition. iii. D1 is a lossy decomposition, but D2 is a lossless decomposition. iv. Both D1 and D2 are lossless decompositions.
Q6: Consider the following statements S1 and S2 about the relational data model: S1: A relation scheme can have at most one foreign key. S2: A foreign key in a relation schema R cannot be used to refer to tuples of R. Which one of the following choices is correct?
i. Both S1 and S2 are false. ii. S1 is false and S2 is true. iii. S1 is true and S2 is false. iv. Both S1 and S2 are true.
Q7: A data consisting of 1,50,000 student-records is stored on a hard disk with block size of 4096 bytes. The data file is sorted on the primary key RollNo. The size of a record pointer for this disk is 7 bytes. Each student-record has a candidate key attribute called ANum of size 12 bytes. Suppose an index file with records consisting of two fields, ANum value and the record pointer to the corresponding student record, is built and stored on the same disk. Assume that the records of data file and index file are not split across disk blocks. The number of blocks in the index file is _______.
Q8: Let S be the following schedule of operations of three transactions T 1, T 2 and T 3 in a relational database system: R 2(Y), R 1(X), R 3(Z), R 1(Y), W 1(X), R 2(Z), W 2(Y), R 3(X), W 3(Z) Consider the statements P and Q below: P: S is conflict-serializable. Q: If T 3 commits before T 1 finishes, then S is recoverable. Which one of the following choices is correct?
i. P is false and Q is true. ii. Both P and Q are false. iii. P is true and Q is false. iv. Both P and Q are true.
Q9: The relation scheme given below is used to store information about the employees of a company, where empId is the key and deptId indicates the department to which the employee is assigned. Each employee is assigned to exactly one department. emp(empId, name, gender, salary, deptId) Consider the following SQL query: select deptId, count (*) from emp where gender = “female” and salary > (select avg(salary) from emp) group by deptId; The above query gives, for each department in the company, the number of female employees whose salary is greater than the average salary of
i. female employees in the department ii. employees in the company iii. employees in the department iv. female employees in the company
Q10: Suppose the following functional dependencies hold on a relation U with attributes P, Q, R, S, and T: P⟶ QR RS⟶ T Which of the following functional dependencies can be inferred from the above functional dependencies?
i. R ⟶ T ii. PS ⟶ Q iii. P ⟶ R iv. PS ⟶ T
Q11: Which one of the following is used to represent the supporting many-one relationships of a weak entity set in an entity-relationship diagram?
i. Diamonds with double/bold border ii. Ovals with double/bold border iii. Ovals that contain underlined identifiers iv. Rectangles with double/bold border
Q12: Consider a relational database containing the following schemas. The primary key of each table is indicated by underlying the constituent fields. SELECT s.sno, s.sname FROM Suppliers s, Catalogue c WHERE s.sno = c.sno AND Cost > (SELECT AVG (cost) FROM Catalogue WHERE pno = ‘P4’ GROUP BY pno); The number of rows returned by the above SQL query is
i. 2 ii. 0 iii. 4 iv. 5
Q13: Consider a schedule of transactions T1 and T2: Here, RX stands for “Read(X)” and WX stands for “Write(X)”. Which one of the following schedules is conflict equivalent to the above schedule?
i. [Schedule 1] ii. [Schedule 2] iii. [Schedule 3] iv. [Schedule 4]
Q14: Consider a relational table R that is in 3NF, but not in BCNF. Which one of the following statements is TRUE?
i. R has a nontrivial functional dependency X→A, where X is not a superkey and A is a prime attribute. ii. R has a nontrivial functional dependency X→A, where X is not a superkey and A is a non-prime attribute and X is a proper subset of some key. iii. A cell in R holds a set instead of an atomic value. iv. R has a nontrivial functional dependency X→A, where X is not a superkey and A is a non-prime attribute and X is not a proper subset of any key.
Q15: Consider a database implemented using B+ tree for file indexing and installed on a disk drive with block size of 4 KB. The size of search key is 12 bytes and the size of tree/disk pointer is 8 bytes. Assume that the database has one million records. Also assume that no node of the B+ tree and no records are present initially in main memory. Consider that each record fits into one disk block. The minimum number of disk accesses required to retrieve any record in the database is ________.
Q16: Consider the following two statements about database transaction schedules: I. Strict two-phase locking protocol generates conflict serializable schedules that are also recoverable. II. Timestamp-ordering concurrency control protocol with Thomas Write Rule can generate view serializable schedules that are not conflict serializable. Which of the above statements is/are TRUE?
i. II only ii. I only iii. Neither I nor II iv. Both I and II
Q17: Which one of the following statements is NOT correct about the B+ tree data structure used for creating an index of a relational database table?
i. Non-leaf nodes have pointers to data records ii. B+ Tree is a height-balanced tree iii. Each leaf node has a pointer to the next leaf node iv. Key values in each node are kept in sorted order
Q18: Let the set of functional dependencies F = {QR → S, R → P, S → Q} hold on a relation schema X = (PQRS). X is not in BCNF. Suppose X is decomposed into two schemas Y and Z, where Y = (PR) and Z = (QRS). Consider the two statements given below: I. Both Y and Z are in BCNF II. Decomposition of X into Y and Z is dependency preserving and lossless Which of the above statements is/are correct?
i. Both I and II ii. I only iii. II only iv. Neither I nor II
Q19: Consider the following relations P(X,Y,Z), Q(X,Y,T) and R(Y,V). How many tuples will be returned by the following relational algebra query?
Q20: A relational database contains two tables Student and Performance as shown below: The primary key of the Student table is Roll_no. For the Performance table, the columns Roll_no. and Subject_code together from the primary key. Consider the SQL query given below: SELECT S.Student_name, sum (P.Marks) FROM Student S, Performance P WHERE P.Marks > 84 GROUP BY S.Student_name; The number of rows returned by the above SQL query is ________.
Q21: In an Entity-Relationship (ER) model, suppose R is a many-to-one relationship from entity set E1 to entity set E2. Assume that E1 and E2 participate totally in R and that the cardinality of E1 is greater than the cardinality of E2. Which one of the following is true about R?
i. Every entity in E1 is associated with exactly one entity in E2. ii. Some entity in E1 is associated with more than one entity in E2. iii. Every entity in E2 is associated with exactly one entity in E1. iv. Every entity in E2 is associated with at most one entity in E1.
Q22: Consider the relations r(A, B) and s(B, C), where s.B is a primary key and r.B is a foreign key referencing s.B. Consider the query Q: r ⋈ (σ B<5 (s)) Let LOJ denote the natural left outer-join operation. Assume that r and s contain no null values. Which one of the following is NOT equivalent to Q?
i. σ B<5 (r ⨝ s) ii. σ B<5 (r LOJ s) iii. r LOJ (σ B<5 (s)) iv. σ B<5 (r) LOJ s
Q23: The following functional dependencies hold true for the relational schema {V, W, X, Y, Z} : V → W VW → X Y → VX Y → Z Which of the following is irreducible equivalent for this set of functional dependencies?
i. V→W W→X Y→V Y→Z ii. V→W W→X Y→V Y→X Y→Z iii. V→W V→X Y→V Y→Z iv. V→W V→X Y→V Y→X Y→Z
**Q24: Consider a database that has the relation schema EMP (EmpId, EmpName, and DeptName). An instance of the schema EMP and a SQL query on it are given below: The output of executing the SQL query is __________. **
Q25: In a database system, unique timestamps are assigned to each transaction using Lamport’s logical clock. Let TS(T 1) and TS(T 2) be the timestamps of transactions T 1 and T 2 respectively. Besides, T 1 holds a lock on the resource R and T 2 has requested a conflicting lock on the same resource R. The following algorithm is used to prevent deadlocks in the database system assuming that a killed transaction is restarted with the same timestamp. if TS(T2)<TS(T1) then T1 is killed else T2 waits. Assume any transaction that is not killed terminates eventually. Which of the following is TRUE about the database system that uses the above algorithm to prevent deadlocks?
i. The database system is deadlock-free, but not starvation-free. ii. The database system is starvation-free, but not deadlock-free. iii. The database system is neither deadlock-free nor starvation-free. iv. The database system is both deadlock-free and starvation-free.
Q26: Consider a database that has the relation schema EMP(EmpId, EmpName, DeptId), and DEPT(DeptName, DeptId). Note that the DeptId can be permitted to a NULL in the relation EMP. Consider the following queries on the database expressed in tuple relational calculus. (I) {t│∃u ∈ EMP(t[EmpName] = u[EmpName] ∧ ∀v ∈ DEPT(t[DeptId] ≠ v[DeptId]))} (II) {t│∃u ∈ EMP(t[EmpName] = u[EmpName] ∧ ∃v ∈ DEPT(t[DeptId] ≠ v[DeptId]))} (III) {t│∃u ∈ EMP(t[EmpName] = u[EmpName] ∧ ∃v ∈ DEPT(t[DeptId] = v[DeptId]))} Which of the above queries are safe?
i. (I), (II) and (III) ii. (I) and (III) only iii. (I) and (II) only iv. (II) and (III) only
Q27: Consider a database that has the relation schema CR(StudentName, CourseName). An instance of the schema CR is as given below: The following query is made on the database. T1 ← π CourseName(σ StudentName=’SA’(CR)) T2 ← CR ÷ T1 The number of rows in T2 is _________.
Q28: An ER model of a database consists of entity types A and B. These are connected by a relationship R which does not have its own attribute. Under which one of the following conditions, can the relational table for R be merged with that of A?
i. Relationship R is one-to-many and the participation of A in R is partial. ii. Relationship R is many-to-one and the participation of A in R is total. iii. Relationship R is one-to-many and the participation of A in R is partial. iv. Relationship R is one-to-many and the participation of A in R is total.
Q29: Consider the following tables T1 and T2. In table T1, P is the primary key and Q is the foreign key referencing R in table T2 with on-delete cascade and on-update cascade. In table T2, R is the primary key and S is the foreign key referencing P in table T1 with on-delete set NULL and on-update cascade. In order to delete record 〈3,8〉 from table T1, the number of additional records that need to be deleted from table T1 is ______.
Q30: Two transactions T 1 and T 2 are given as • T 1: r 1(X) w 1(X) r 1(Y) w 1(Y) • T 2: r 2(Y) w 2(Y) r 2(Z) w 2(Z) where r i(V) denotes a read operation by transaction T i on a variable V and w i(V) denotes a write operation by transaction T i on a variable V. The total number of conflict serializable schedules that can be formed by T 1 and T 2 is _______.
Q31: In a B+ tree, if the search-key value is 8 bytes long, the block size is 512 bytes and the block pointer size is 2 bytes, then the maximum order of the B+ tree is ________.
Q32: Which of the following is NOT a superkey in a relational schema with attributes V, W, X, Y, Z and primary key VY?
i. VWXYZ ii. VWXY iii. VWXZ iv. VXYZ
Q33: Which of the following is NOT a part of the ACID properties of database transactions?
i. Deadlock-freedom ii. Isolation iii. Consistency iv. Atomicity
Q34: A database of research articles in a journal uses the following schema. (VOLUME, NUMBER, STARTPAGE, ENDPAGE, TITLE, YEAR, PRICE) The primary key is (VOLUME, NUMBER, STARTPAGE, ENDPAGE) and the following functional dependencies exist in the schema. • (VOLUME, NUMBER, STARTPAGE, ENDPAGE) → TITLE • (VOLUME, NUMBER) → YEAR • (VOLUME, NUMBER, STARTPAGE, ENDPAGE) → PRICE The database is redesigned to use the following schemas. • (VOLUME, NUMBER, STARTPAGE, ENDPAGE, TITLE, PRICE) (VOLUME, NUMBER, YEAR) Which is the weakest normal form that the new database satisfies, but the old one does not?
i. BCNF ii. 3NF iii. 2NF iv. 1NF
Q35: Consider the following two phase locking protocol. Suppose a transaction T accesses (for read or write operations), a certain set of objects{O 1,…,O k}. This is done in the following manner: Step1 : T acquires exclusive locks to O 1 ,…,O k in increasing order of their addresses. Step2 : The required operations are performed. Step3 : All locks are released. This protocol will
i. guarantee serializability and deadlock-freedom ii. guarantee neither serializability nor deadlock-freedom iii. guarantee serializability but not deadlock-freedom iv. guarantee deadlock-freedom but not serializability
Q36: B+ Trees are considered BALANCED because
i. The number of records in any two leaf nodes differ by at most 1. ii. The number of children of any two non-leaf sibling nodes differ by at most 1. iii. The lengths of the paths from the root to all leaf nodes differ from each other by at most 1. iv. The lengths of the paths from the root to all leaf nodes are all equal.
Q37: Suppose a database schedule S involves transactions T 1, …, T n. Construct the precedence graph of S with vertices representing the transactions and edges representing the conflicts. If S is serializable, which one of the following orderings of the vertices of the precedence graph is guaranteed to yield a serial schedule?
i. Ascending order of transaction indices ii. Breadth-first order iii. Depth-first order iv. Topological order
Q38: Consider the following database schedule with two transactions, T 1 and T 2. • S = r 2(X); r 1(X); r 2(Y); w 1(X); r 1(Y); w 2(X); a 1; a 2 where r i(Z) denotes a read operation by transaction T i on a variable Z, w i(Z) denotes a write operation by T i on a variable Z and a i denotes an abort by transaction T i. Which one of the following statements about the above schedule is TRUE?
i. S is non-recoverable ii. S is recoverable, but has a cascading abort iii. S does not have a cascading abort iv. S is strict
Q39: Consider the following database table named water_schemes : The number of tuples returned by the following SQL query is ___________.
Q40: SELECT operation in SQL is equivalent to
i. The selection operation in relational algebra ii. The selection operation in relational algebra, except that SELECT in SQL retains duplicates iii. The projection operation in relational algebra iv. The projection operation in relational algebra, except that SELECT in SQL retains duplicates
Q41: Consider an Entity-Relationship (ER) model in which entity sets E 1 and E 2 are connected by an m:n relationship R 12, E 1 and E 3 are connected by a 1:n (1 on the side of E 1 and n on the side of E 3) relationship R 13. E 1 has two single-valued attributes a 11 and a 12 of which a 11 is the key attribute. E 2 has two single-valued attributes a 21 and a 22 is the key attribute. E 3 has two single-valued attributes a 31 and a 32 of which a 31 is the key attribute. The relationships do not have any attributes. If a relational model is derived from the above ER model, then the minimum number of relations that would be generated if all the relations are in 3NF is __________.
Q42: Consider the following relations: Consider the following SQL query. SELECT S. Student_Name, sum(P.Marks)FROM Student S, Performance PWHERE S.Roll_No = P.Roll_NoGROUP BY S.Student_Name The number of rows that will be returned by the SQL query is ______.
Q43: Consider the following transaction involving two bank account x and y. read(x); x:= x-50; write(x); read(y); y:= y+50; write(y) The constraint that the sum of the accounts x and y should remain constant is that of
i. Atomicity ii. Consistency iii. Isolation iv. Durability
Q44: With reference to the B+ tree index of order 1 shown below, the minimum number of nodes (including the Root node) that must be fetched in order to satisfy the following query:”Get all records with a search key grater than or equal to 7 and less than 15″ is _______.
Q45: Consider a simple check-pointing protocol and the following set of operations in the log. (start, T4); (write, T4, y, 2, 3); (start, T1); (commit, T4); (write, T1, z, 5, 7); (checkpoint); (start, T2); (write, T2, x, 1, 9); (commit, T2); (start, T3); (write, T3, z, 7, 2); If a crash happens now and the system tries to recover using both undo and redo operations, what are the contents of the undo list and the redo list
i. Undo T3, T1; Redo T2 ii. Undo T3, T1; Redo T2, T4 iii. Undo: none; redo: T2, T4, T3, T1 iv. Undo T3, T1; T4; Redo: T2
Q46: Consider two relations R 1(A,B) with the tuples (1,5), (3,7) and R 2(A,C) = (1,7), (4,9). Assume that R(A,B,C) is the full natural outer join of R 1 and R 2. Consider the following tuples of the form (A,B,C): a = (1.5,null), b = (1,null,7), c = (3,null,9), d = (4,7,null), e = (1,5,7), f = (3,7,null), g = (4,null,9). Which one of the following statements is correct?
i. R contains a,b,e,f,g but not c, d. ii. R contains all of a,b,c,d,e,f,g iii. R contains e,f,g but not a,b iv. R contains e but not f,g
Q47: Consider the relation X(P, Q, R, S, T, U) with the following set of functional dependencies F = { {P, R} → {S,T}, {P, S, U} → {Q, R} } Which of the following is the trivial functional dependency in F +, Where F + is closure of F?
i. {P,R}→{S,T} ii. {P,R}→{R,T} iii. {P,S}→{S} iv. {P,S,U}→{Q}
Q48: Consider the following relation Cinema (theater, address, capacity) Which of the following options will be needed at the end of the SQL query SELECT P1. address FROM Cinema P1 Such that it always finds the addresses of theaters with maximum capacity?
i. WHERE P1.capacity >= All (select P2.capacity from Cinema P2) ii. WHERE P1.capacity >= Any (select P2.capacity from Cinema P2) iii. WHERE P1.capacity > All (select max(P2.capacity) from Cinema P2) iv. WHERE P1.capacity > Any (select max(P2.capacity) from Cinema P2)
Q49: Consider a B+ tree in which the search key is 12 bytes long, block size is 1024 bytes, record pointer is 10 bytes long and block pointer is 8 bytes long. The maximum number of keys that can be accommodated in each non-leaf node of the tree is ______.
Q50: Given the function F=P′+QR, where F is a function in three Boolean variables P,Q and R and P′=!P, consider the following statements. (S1)F=∑(4,5,6) (S2)F=∑(0,1,2,3,7) (S3)F=Π(4,5,6) (S4)F=Π(0,1,2,3,7) Which of the following is true?
i. (S1)-False, (S2)-True, (S3)-True, (S4)-False ii. (S1)-True, (S2)-False, (S3)-False, (S4)-True iii. (S1)-False, (S2)-False, (S3)-True, (S4)-True iv. (S1)-True, (S2)-True, (S3)-False, (S4)-False
Solutions
Q1: ii – The same undo and redo list will be used while recovering again.
Q2: 820 – The expected number of tuples satisfying the condition is 1200 * (15/15) * (20/20), but adjusted for ranges: probability (15 choices for A, 20 for B) leads to 1200 * (1/15 * 1/20) wait, actually it’s the number of distinct (A,B) pairs, but question is incomplete in text, assumed standard calculation 820.
Q3: ii – Employee numbers of all employees whose age is not the minimum.
Q4: iv – S1 is not conflict serializable (cycle), S2 is.
Q5: ii – D1 lossless, D2 lossy.
Q6: i – Both false.
Q7: 698 – (150000 * 19 bytes) / 4096 ≈ 698 blocks.
Q8: iii – P true, Q false.
Q9: ii – Average over all employees in the company.
Q10: ii, iii, iv – PS → Q, P → R, PS → T can be inferred.
Q11: i – Diamonds with double border for many-one weak relationships.
Q12: iii – 4 rows.
Q13: i – Schedule 1 is equivalent.
Q14: i – For 3NF not BCNF, A prime.
Q15: 4 – 3 levels + 1 leaf.
Q16: iv – Both true.
Q17: i – Non-leaf don’t point to data.
Q18: iii – II only.
Q19: 1 – 1 tuple.
Q20: 5 – 5 rows.
Q21: i – Exactly one.
Q22: iii – Not equivalent.
Q23: iii – Irreducible set.
Q24: 2.6 – Output 2.6.
Q25: iv – Both free.
Q26: i – All safe.
Q27: 4 – 4 rows.
Q28: ii – Many-to-one total.
Q29: 0 – No additional.
Q30: 54 – 54 schedules.
Q31: 52 – Order 52.
Q32: iii – VWXZ not superkey.
Q33: i – Not deadlock-freedom.
Q34: iii – 2NF.
Q35: i – Both guaranteed.
Q36: iv – Equal lengths.
Q37: iv – Topological.
Q38: iii – No cascading.
Q39: 2 – 2 tuples.
Q40: iv – Projection with duplicates.
Q41: 4 – 4 relations.
Q42: 2 – 2 rows.
Q43: ii – Consistency.
Q44: 5 – 5 nodes.
Q45: i – Undo T3 T1, Redo T2.
Q46: iii – e f g.
Q47: iii – Trivial {P,S}→S.
Q48: i – >= All.
Q49: 50 – 50 keys.
Q50: i – S1 false, S2 true, S3 true, S4 false.