0% found this document useful (0 votes)
163 views

Database PYQ

Uploaded by

Anushree Jaiswal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
163 views

Database PYQ

Uploaded by

Anushree Jaiswal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 63
== Sl. | Topic | Page No. Databases = = Contents 1. ER-Model... 2. Database Design: Functional Dependencies and Normalizatior 3. Structured Query Language (SQL) 4, Relational Model: Relational Algebra and Tuple Calculus 5. Transactions & Concurrency Control File Structures concurrency control. Analysis of Previous GATE Papers Databases Syllabus : ex. model, relational model relational algebra, tuple calculus), Database design (integrity constraints, normal forms), Query languages (SQL File structures (sequential files, indexing, B and B+ trees), Transactions and ‘Exam | 1 Mark | 2Marks | 3 Marks |5Marks| Total | |. Exam Year | Ques. | Ques. | Ques. | Ques. | Marks | Year 1990 | - = - 2008 1 5 | 4M so | - - - 2009 = 5 | 10 1902 | = = 2010 Z ee 1903 | i = 2011 = 2| 4 joo | 3 e 3 2012 2 5 [2 1995 | - 1 2 aye S See ape 7 2 | | 21sec | 2 3 [ee jer z} a | [zor sev2 [2 See Tle 7 a | | 2otasets | 2 356 2oisse-t | 2 2/6 1999 | 4 3 . 10 2015set2 | 2 2= se. 2000 | 2 3 - e | Lasse | 2 Zee 1 ae i 2oieseti | 4 1| 6 8 ee ee = 2oieset2 | 2 2/6 oar s 8 | [aorta [2 ab COOH fate 2 2 || 2oi7set2 | 2 3 fs 205 | 3 4 1" 2018 2 2 | 6 2006 | 1 4 9 2019 2 ae 2007 | - 6 E 12 2020 2 a [8 ER-Model 1.1 Itis desired to design an object-oriented employee record system for a company. Bach employee has aname, unique id and salary. Employees belong to different categories and their salary is determined by their category. The functions getName, getld and computeSalary are required, Given the class hierarchy below, possible locations for these functions are: ()getldis implemented in the superclass Gi) getldis implemented in the subclass (ii getName is an abstract function in the superclass (Gv) getName is implemented in the superclass (v) getName is implemented in the subclass (vi) getSalary is an abstract function in the superclass (vii)getSalary is implemented in the superclass (viii) getSalary is implemented in the subclass Manager Engineer Secretary Choose the best design ©) ©, Gv), (i, (iti) ©) (, Gv), (vii) © Gi), Gil), (), (Wi), (wii) ‘ © Gi, (0), [2004:2 Marks} 1.2. Consider the following entity relationship diagram (ERD), where two entities E1 and B2 have a relation R of cardinality 1: m a }—<@p—[ 2 | ‘The attributes of E1 are A11, Al2 and A13 where A is the key attribute. The attributes of E2 are A21, A22 and A23 where A21 is the key attribute and A23 is a multi-valued attribute Relation R does not have any attribute. A relational database containing minimum number of tables with each table satisfying the requirements of the third normal form (3NF) is, designed from the above ERD. The number of tablesin the database is f@2 3 os @4 [2004 : 2 Marks} 13 Consider the entities ‘hotel room’, and ‘person’ with a many to many relationship ‘lodging’ as shown below: (sl ~<(C269>— [Ta Ifwe wish to store information about the rent payment to be made by person (s) occupying different hotel rooms, then this information should appear as an attribute of (@) Person () Hotel Room (© Lodging (@ None of these [2005 : 1 Mark] 14 Let E, and E, be two entities in an B/R diagram with simple single-valued attributes. R, and R, are two relationships between E, and E,, where R, is one-to-many and R, is many-to- many. R, and R, do not have any attributes of their own, What is the minimum number of tables required to represent this situation in the relational model? @2 os oO4 @5 [2005 : 2 Marks} 15. The following table has two attributes A and C where Ais the primary key and Cis the foreign key referencing A with on-delete cascade, Ale 6l4 ‘The set of all tuples that must be additionally deleted to preserve referential integrity when the tuple @ 4) is deleted is: DEEASY | Databases | 561 (@) (,4)and 6,4) ©) (,2)and (7,2) © ©,2)(7,2) and 9, 5) @1 [2005 :2 Marks} ~ Common Data for Q.1.6&Q.1.7 Consider the following BR diagram @29® ®® @® << 1.6 Theminimum numberof ables needed to represent M,N, P, R1, R2is @2 b) 3 o4 @5 (2008: 2 Marks] 1.7 Which ofthe following is a correct attribute set, for one of the tables for the correct answer to the above question? (@) (M1, M2, M3, Pty () (M1, P1, N1, N2} (© (M1, P1, Ni} @ (M1, Ply (2008: 2 Marks} 1.8. Given the basic ER and relational models, which of the following is INCORRECT? (@) Anattribute of an entity can have more than one value (0) An attribute of an entity can be composite (©) Ina row of a relational table, an attribute can have more than one value (@ Ina row of a relational table, an attribute can have exactly one value or a NULL value (2012: 1 Mark] 19 Consider an Entity-Relationship (ER) model in which entity sets B, and E, are connected by anm:nrelationship RE, and E, are connected bya1:n (Lon the side of E, and non the side of E,) relationship R,s- E, has two single-valued attributes, and a, of which a,, is the key attribute. E, has two single valued attributes ap, and a,, of which ay, is the key attribute. has two single-valued attributes a and ay, of which ay, is the key attribute. The relationships do not have any attributes. 1.10 au 112 Ifa 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 BNF is [2015 (Set-1) :2 Marks} ‘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? (@) Relationship R is one-to-many and the participation of A in R is total. (>) Relationship R is one-to-many and the participation of A in R is partial (0 Relationship R is many-to-one and the participation of A in R is total. @ Relationship R is many-to-one and the participation of A in R is partial [2017 (Set-2): 1 Mark} Inan Entity-Relationship (ER) model, suppose Risa many-to-one relationship from entity set El to entity set E2. Assume that E1 and E2 participate totally in R and that the cardinality of El is greater than the cardinality of B2. Which one of the following is true about R? @) Every entity in E1 is associated with exactly one entity in B2. ) Some entity in EI is associated with more than one entity in E2. (© Every entity in E2is associated with exactly one entity in B1. (@ Every entity in B2 is associated with at most one entity in BI. [2018: 1 Mark] Which one ofthe following is used to represent the supporting many-ore relationships of a weak entity sot in an entity-relationship diagram? (@) Rectangles with double/bold border (©) Ovals with doublefbold border (© Ovals that contain underlined identifiers (@ Diamonds with double/bold border [2020: 1 Mark] 562 | GATE Previous Years Solved Papers: [@] | MADEEASY 11 (a) 12 (b) 111 @ 112 @) EEE «se ie Superclass hide the information to the outside world so each id of an employee must be implemented in superclass. Name isalso an important attribute of employee so must be implemented in the superclass. Salary of an employee is differ by category and department so it is a function must be implemented in subclass. ie Given information is: 13 © Relation table R combine with entity £2 (since 1-many relation, Relation combine with many side, in case of partial participation) E1(A11, A12, A13) with key ALL RE2(A21, A22, A23, ALT) with In REZ partial dependence A21 > A22, ALL present, So, not in 2NF. To remove it we need 2 separate table ie. a E1(A11, Al2, A13) with key ALL RELI (A21, A23) with key A21, A: ‘E22 (A21, A22, Al1) with key A21 All the three tables are now in 3NF form. lo Hotel Room According to given E-R diagram, Hotel Room contain all the information about Hotel Room and Person contain all information related to Person. So, when any person do a payment for rent of room will be stored inside Lodging relation, since itis connected two entities. 14 () 15 © % 16 (b) 17 (@) 18 © 110 @ R, key is b, R, key is ab, B, key isa and E, key ish, R, and B, can merge because keys are same. .- Bj, R,Ey and R, tables are required. (ec) Tf, 4)is deleted then 2s the primary key but in, 2) and (7, 2), 2 is the foreign key so these mnust be deleted, The primary key for (5, 2) and (7, 2)is5 and 7 respectively but in (9,5), 5is the foreign key soit is also deleted. ae R, relationship merges to entity set (M) R,relationship is weak entity set N in one table ‘M,(M, M, M,P,) PC, P,) NR, (PN, N,) ‘Total 8 relational tables required. Hae ‘The correct attribute set is (M1, M2, M3, P1} He Option (a) is correct as there are multivalued attribute e.g, phone no (attribute) Option (b) is also correct. Option (d) ‘Null’ values are allowed in a row of | relational database (Null value arc constraints only for primary keys). Asin NF also we remove multivalued attribute. ~: Option (¢) is incorrect. 5 ERs 039%1) {051 9 4553} E,(a41%2) {41 > a} Fao(Qu101) Ey(dqyyq) (4, > Gg} Total minimum 4 tables required. y We Entity sets A, B Relationship set R Relation R merges with that of A. u A oO B e d e * Many to one relationship set can merge towards entity set ‘A’. + Partipation towards A side can be total | partial le 4 M 1 EL B E1 entries > E2 entities BOR OBR 2 Every entity in E1 is associated with exactly one entity in E2. Many: One cardinality and total participation both E1 E2 ends. So that number of records of E1= Number of records in R. EL R Ee A AB B a} fa) fo oy a by b a | fos i a | [ot 5 oO, & wer Retaloehip st Weak ently set [Diamond shape with ‘doublelbold borders) Database Design: Func Dependencies and Normalization 21 State True or False with reason ‘There is always a decomposition into Boyce-Codd normal form (BCNF) that is lossless and dependency preserving, [1994: 1 Mark] 22 (a) Consider the relation scheme R(A, B, C) with the following functional dependencies: AB>C CoA Show that the scheme R is the Third Normal Form (3NF) but not in Boyee- Code Normal Form (BCNF). (&) Determine the minimal keys of relation R. [1995 : 2 Marks] 23. Fora database relation R(a, b,c, d), where the domains ofa, b,c, d include only atomic values, only the following functional dependencies and those that can be inferred from them hold: ase bod This relation is @) in first normal form but not in second normal form (b) in second normal form but not in third normal form , (9 in third normal form (@ None ofthe above [1997: 2 Marks] 24 Let R (a, b, c) and S(d, e, f) be two relations in which dis the foreign key of S that refers to the primary key of R. Consider the following four operatiorison Rand S @ InsertintoR i) InsertintoS (ii)Delete from R — (iv)Delete from S Which of the following is true about the referential integrity constraint above? @) None of (i), (i), Gi) or (iv) can cause its violation (b) All of (i), Gi), Gii) and (iv) can cause its violation 26 27 (©) Both (i) and (iv) can cause its violation (@ Both (ii) and (ii) can cause its violation [1997: 2 Marks} Which normal form is considered adequate for normal relational database design? (a) 2NF (b) 5 NF (© 4NF @ 3NF 2 [1998 1 Mark] ‘There are five records in a database. Name [Age | Occupation | Category Rama | 27] CON A Abdul | 22] ENG A Jeniffer | 28 | DOC B Maya | 32 | SER D Dev_| 24 | _ MUS c ‘There is an index file associated with this and it contains the values 1, 3, 2, 5 and 4. Which one of the fields is the index built from? (@) Age (b) Name (© Occupation —_—_(@) Category [1998 :1 Mark] Consider the following database relations containing the attributes Book_id Subject_Category_of book Name_of_Author Nationality_of Author With book_id as the primary key. (@) Whatis the highest normal form satisfied by this relation? () Suppose the attributes Book title and Author_address are added to the relation, and the primary key is changed to {Name_of_Author, Book_title}, what will be the highest normal form satisfied by the relation? [1998: 2 Marks} EASY | Databases | 565 8 LetR=(A, B,C, D, E, F) be a relation scheme with the following dependencies C + F, EA, ECD, AB. Which of the following is a key for R? @ cD (@ AE () EC @ac [1999: 1 Mark] Consider the schema R = (ST U V) and the dependencies S + T, T+ U, U+ Vand VS. Let R = (R1 and R2) be a decomposition such. that R10 R2=4. The decomposition is (@) not in 2NF () in 2NF but not 3NF (© in 3NF but not in 2NF (@ in both 2NF and 3NF [1999: 2 Marks] Given the following relation instance XYZ * a2 2 ‘Which of the following functional dependencies are satisfied by the instance? (@) XY >ZandZ>Y @) YZ>X and Y¥ 3% © YZ>XandX 3% (@ XZ4Yand YX (2000: 2 Marks} Consider a schema R(A,B,C,D) and functional dependencies A + B and C + D. Then the decomposition of R into R,(AB) and R,(CD) is (@ dependency preserving and lossless join (©) lossless join but not dependency preserving © dependency preserving but not lossless join (@ not dependency preserving and not lossless join [2001 : 1 Mark] R,B,C, D)isa relation. Which ofthe following does not have a lossless join, dependency preserving BCNF decomposition? (@) A>B,B>CD ) A>B,B3C,C>D © AB+C,C+AD @ A>BCD [2001:2Marks) Relation R with an associated set of functional dependencies, F, is decomposed into BCNF. The a4 215 216 redundancy (arising out of functional dependencies) in the resulting set of relation is (a) Zero () More than zero but less than that of an equivalent 3NF decomposition (© Proportional to the size of F* (@ Indeterminate [2002 :1 Mark] Relation Ris decomposed using a set of functional dependencies, F, and relation $ is decomposed using another set of functional dependencies, G. ‘One decomposition is definitely BCNF, the others definitely 3 NF, butit is not known which is which, To make a guaranteed identification, which one of the following tests should be used ‘on the decompositions? (Assume that the closures of Fand G are available). (@) Dependency-preservation (b) Lossless-join (© BNF definition (@ 2NF definition [2002 : 2 Marks] From the following instance of a relation scheme R(A, B, C), we can conclude that: no (@) A functionally determines B and B functionally determines C ©) A functionally determines B and B does not, functionally determines C (© Bdoes not functionally determines C (@ A does not functionally determines Band B does not functionally determines C (2002: 2 Marks} Consider the following functional dependencies inadatabase: Data_of Birth Age Age — Eligibility Name — Roll_number Roll number—> Name Course_number—> Course_name Course_number-> Instructor (Roll_number; Course_number) > Grade 566 | GATE Previous Years Solved Papers. | MADE Easy The relation (Roll_number; Name, (@ 1 NF () 2NF Date_of birth, Age) is © 3 NF (@ None of these 217 218 219 2.20 (@) insecond normal form but notin third normal form () in third normal form but not in BCNF (© inBCNF (@ innone of the above [2003 : 2 Marks] Consider the following relation schema pertaining toa students database: Student (rolino, name, address) Enroll (rollno, courseno, coursename) where the primary keys are shown underlined. ‘The number of tuples in the student and Enroll tables are 120 and 8 respectively. What are the maximum and minimum number of tuples that can be present in (Student * Enroll), where *” denotes natural join? fa) 8,8 (b) 120,8 © 960,8 (@) 960, 120 [2004 : 1 Mark] ‘The relation scheme student Performance (name, courseNo, rollNo, grade) has the following functional dependencies: name, courseNo — grade RollNo, courseNo— grade name ~ rollNo rollNo—> name ‘The highest normal form ofthis elation scheme is (@) 2NF ( 3NF (©) BONF @ 4NF [2004 :2 Marks} A relation Empat] is defined with attributes empcode (unique), name, street, city, state and pincode, For any pincode, there is only one city and state. Also, for any given street, city and state, there is just one pincode. In normalization terms, Empat isa relation in (@) INF only () 2NF and hence also in INF (© SNF and hence also in 2NF and INF @ BCNF and hence also in 3NF,2NF an 1NF [2004 : 2 Marks} A table has fields Fl, F2, F3, F4, F5 with the following functional dependencies FL F3, F2 > F4, (FI, F2) > F5 In terms of Normalization, this table is in 2.21 222 2.23 2.24 2.25 [2005 : 1 Marky Which-one of the following statements about normal forms is FALSE? (@) BCNF is stricter than 3 NF (0) Loss less, dependency-preserving decomposition into 3 NF is always possible (© Loss less, dependency-preserving decomposition into BONF is always possible (@ Any relation with two attributes is BCNF [2005 :1 Marky Consider a relation scheme R= (A, B,C, D, E, H) on which the following functional dependencies hold: {A>B, BC+D,E>C,D A} What are the candidate keys of R? (a) AE, BE (b) AE, BE, DE (9 ABH, BEH,BCH (@ AEH, BEH, DEH [2005 : 2 Marks} Ina schema with attributes A, B, C, D and E following set of functional dependencies are given. AOB AvC CDsE BoD EsA Which of the following functional dependencies is NOT implied by the above set, (@) CD > AC @) BD > CD @ BC+ CD @ AC > BC [2005 : 2 Marks} Consider the relations r,(P,Q.R) and r, (R,S,1) with primary keys P and R respectively. The relation r, contains 2000 tuples and r, contains 2500 tuples. The maximum Size of the join 1 o31, is: (@ 2000 2500 (© 4500 (@ 5000 [2006 : 1 Mark] Consider a relation R with five attributes V, W, X, Y, and Z. The following functional dependencies hold : VY > W, WX = Z, and ZY > V. Which of the following is a candidate key for R? (a) VXZ (b) VxY () VWXY (@ VWXYZ [2006 : 2 Marks] ay Dut ng ng ale +k H) ies ss} iE ven ‘ies rk] Ww, nal and ate ks} EEASY | Databases | 567 16 The following functional dependencies are given: AB > CD, AF > D, DE > F, CG, FSEG3A Which one of the following options is false? (@) {CF}*={ACDEFG} (b) {BG} ={ABCDG} (©) {AF}*={ACDEFG} (@ {ABY*={ACDFG} [2006 :2 Marks} Which one of the following statements is FALSE? (@) Any relation with two attributes is in BCNF () Arelation in which every key has only one attribute is in 2NF © A prime attribute can be transitively dependenton a key in SNF relation (@ Aprime attribute can be transitively dependent on akey in a BCNF relation. [2007:2 Marks) Consider the following implications relating to functional and multivalued dependencies given below, which may or may not be correct, @ IfA>B and AC then A>BC i) If A+B and A3C then A>—BC (ii) If A>—BC and AB then A3C Gv) If A4BC and AB then AC Exactly how many of the above implications are valid? @o @1 @2 @3 [2007 : 2 Marks} Let R (A, B,C, D) be a relational schema with the following functional dependencies: A>B.B>C,C+DandD +B. ‘The decomposition of R into (A, B),(B, ©), (B,D) @) Gives a lossless join, and is dependency preserving (0) Gives a lossless join, but is not dependency preserving (©) Does not give a lossless join, but is dependency preserving @ Does not give a lossless join and is not dependency preserving [2008 : 2 Marks} Let R(A, B,C, D, E, P, G) bea relational schema in which the following functional dependencies are known to hold: AB CD,DE-P,C>E,P>CandB>G. 231 2.32 2.88, ‘The relational schema Ris (@) in BCNF (©) in 8NF, but not in BCNF (© in 2NF, but not in 3NF @ not in 2NF [2008 : 2 Marks} Consider the following relational schemes for a library database: Book (Title, Author, Catalog_no, Publisher, Year, price) Collection (Title, Author, Catalog_no) which the following functional dependencies: L. TitleAuthor— Catalog no IL. Catalog_no Title Author Publisher Year IIL Publisher Title Year > Price Assume (Author, Title} is the key for both schemes: which of the following statements is true? (@) Both Book and Collection are in BCNF (©) Both Book and Collection are in 3NF only (© Book is in 2NF and Collection is in 3NF (@ Both Book and Collection are in 2NF only (2008: 2 Marks} ‘The following functional dependencies hold for relations R(A, B, C) and SB, D, B) BoA AoC The relation R contains 200 tuples and the relation S contains 100 tuples. What is the ‘maximum number of tuples possible in the natural join R >< $? (@) 100 © 300 (b) 200 (@ 2000 [2010: 2 Marks] Consider a relational table with a single record from each registered student with the following attributes. 1. Registration_Num: Unique registration number ofeach registered student 2, UID: Unique identity number, unique at the national level for each citizen 3, BankAccount_Num: Unique account number at the bank. A student can have multiple accounts or joint accounts. This attribute stores the primary account number 4, Name: Name of the student 5. Hostel_Room: Room number of the hostel ‘Which of the following options is INCORRECT? GATE Previous Years Solved Papers : (@J | MADE (@) BankAccount_Num isa candidate key (6) Registration Num can be a primary key (© UlDisa candidate key fall students are from the same country (@ IfSisa superkey such that $m UIDis NULL then Su UID is also a superkey (2011 :1 Mark] 234 Which of the following is TRUE? (@) Every relation in 3NF is also in BCNF () A relation R is in 3NF if every non-prime attribute of Ris fully functionally dependent onevery key of R (©) Every relation in BCNF is also in 3NF (@ No relation can be in both BCNF and 3NF {20121 Mark] Linked Answer Questions 2.35 and 2.36 Relation R has eight attributes ABCDEFGH. Fields of Reontain only atomie values. F={CH+G,A—BC, B+ CFH, EA, P+ EG}is set of functional dependencies (FDs) so that Fis exactly the set of FDs that hold for R. 235 How many candidate keys does the relation R have? @) 3 ) 4 @5 @6 [2013:2 Marks} 236 The relation Ris (a) in LNF, but not in 2NF. (®) in 2NF, but not in SNF. (© in 3NP, but not in BCNF. (@ inBONF. (2013: 2Marks] 2.37 Consider the relation scheme R=(E, F, G, H, I, J, K, L, M,N) and the set of functional dependencies {{E,F} > {G}, {F} > {LJ}, {E,H} > (K, L}, {K} > {M}, {L} > {N}} on R. What is the key for R? (@) {E, FY (b) {E, FH} OUR HKD @ te} [2014 (Get-1): 1 Mark] 2.38 Given the following statements: SI: A foreign key declaration can always be replaced by an equivalent check assertion in SQL. $2: Given the table R(a,b,c) where a and b together form the primary key, the following isa valid table definition 2.39 2.40 241 242 CREATE TABLES ( a INTEGER, aINTEGER, e INTEGER, PRIMARY KEY (@), FOREIGN KEY (a) references R) Which one of the following statements is CORRECT? (@) S1is TRUE and 82 is FALSE. (0) Both $1 and $2 are TRUE. (©) S1is FALSE and $2 is TRUE. (@ Both $1 and S2 are FALSE, [2014 (Set-1): 1 Mark] Given the following two statements: S1: Every table with two single-valued attributes isin INF, 2NF, 3NF and BNF. $2: AB C, D> E, E> Cisa minimal cover for the set of functional dependencies AB> C,D+E,AB>E, EC. Which one of the following is CORRECT? (@) S1is TRUE and 82 is FALSE. () Both $1 and $2 are TRUE. (© Slis FALSE and $2is TRUE. (@ Both $1 and S2 are FALSE. [2014 (Set-1):2 Marks} ‘The maximum number of superkeys for the relation schema R(E,F,G,H) with Eas the key is {2014 (Set-2): 1 Mark] Given an instance of the STUDENTS relation as shown below: [SadenaD | StadenNome | StudentBmal | Stadonthgs [CPI us| Shankar [shankar | x __[ 90 ‘at | Seati__[ewaioe is [s, ess |_Stankar [santana | 19 [oa sete [Swati [ewan = [es 1165 | Gaowsh [aunebaeiod | 19 at For (StudentName, StudentAge) to be a key for this instance, the value Xshould NOT be equal to . [2014 (Set-2): 1 Mark] A prime attribute of a relation scheme R is an attribute that appears (@) inall candidate keys of R. () in some candidate key of R. (© ina foreign key of R (@ only in the primary key of R. [2014 Get-3):1 Mark] EASY | Databases | 569 Consider the relation X(P, Q, R, S, 7, U) with the following set of functional dependencies F={ PRS, D AP, S, U} > {@, Rh 3 Which of the following is the trivial functional dependency in F* is closure of F? @ PRS T PRR 7 ORS OPS YQ [2015 (Set-3): 1 Mark] Which of the following is NOT a superkey in a relational schema with attributes V, W, X,Y, Z and primary key VY? @ VXxXYZ ) VWXZ © vwxy @Vwxyz [2016 (Set-1) : 1 Mark] 245 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 ks] functional dependencies exist in the schema. the (VOLUME, NUMBER, STARTPAGE, vis ENDPAGE) TITLE (VOLUME, NUMBER) —> YEAR ck] (VOLUME, NUMBER, STARTPAGE, a ENDPAGE) ~> PRICE The database is redesigned to use the following z schemas. E ‘ (VOLUME, NUMBER, STARTPAGE, fi ENDPAGE, TITLE, PRICE) 3 (VOLUME, NUMBER, YEAR) a Which is the weakest normal form that the new wey database satisfies, but the old one does not? ual (@ INF () 2NF (© 3NF (@ BCNF rk] [2016 (Set-1): 1 Mark] an 246 The following functional dependencies hold true for the relational schema R{V, W, X, Y, Z} vow WX Yo VX YoZ rk] 247 248 Which of the following is irreducible equivalent for this set of functional dependencies? @ Vow 0 Vow Vox WoX Yov Yov Yoz You © V5W @ Vow Vox WX Yov Yov YoX YoXx Yoz YoZ [2017 (Set-1):1 Mark] Consider the following tables 7, and 7, ty % p[e@|[r]s Tyo zy 2 ae a ]a 113 a] s [a a] 6} 9 s]7 a | 5 a] ois In table 7,, Pis the primary key and Q is the foreign key referencing R in table 7, with on- delete cascade and on-update cascade. In table 1,, Riis the primary key and S is the foreign key referencing Pin table T, with on-delete set NULL and on-update cascade. In order to delete record (3, 8) from table 7,, the number of additional records that need to be deleted from table Tis. [2017 (Set-2): 1 Mark] Consider the following four relational schemas. For each schema, all non-trivial functional dependencies are listed. The underlined attributes are the respective primary keys. Registration (rollno, courses) Field ‘courses’ is a set-valued attribute containing the set of courses a student has registered for. Non-trivial functions dependency: rollno ~ courses Schema I: Schema lI: Registration (rollno, courseid, email) ‘Non-trivial functional dependencies: rollno, courseid -> email email > rollno 570 | SchemalIII: Registration (rollno, courseid, marks, grade) Non-trivial functional dependencies: rollno, courseid — marks, grade marks — grade Registration (rollno, courseid, credit) Non-trivial functional dependencies: rollno, courseid — credit Schema IV: courseid credit Which one of the relational schemas above is in 8NF but not in BCNF? (@) Schema (©) Schema Il (©) Schema III @ — SchemalV [2018: 2 Marks] 2.49 Let the set of functional dependencies F = {QR +8,RP, 8 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: 1. Both Y andZ are in BCNF IL, Decomposition of X into Y and Zis dependency preserving and lossless EQEIIIEN Database Design: Functional Dependencies and Normalization 23 (a) 24 @ 25 @) 26 (© 28 (b) 29 (a) 210 (b) 211 () 212 © 213 (a) 214 (c) 215 (©) 216 (d) 2.17 (a) 218 (b) 219 (b) 220 (a) 2.21 (©) 2.22 (@) 223 (b) 224 (a) 225 (b) 226 (c,d) 227 (d) 2.28 (c) 229 (c) 230 (d) 231 () 232 (a) 283 (a) 234 (©) 235 (b) 236 (a) 237 (b) 238 (d) 239 (a) 2.42 (b) 243 (c) 244 (b) 245 (b) 246 (a) 248 (b) 2.49 (2) 2.50 (a) [EEIRENEIEM Database Design: Functional Dependencies and Normalization EEEso1: Himsa False ‘Sometimes, there is no decomposition into BCNF that is dependency-preserving. For example: Consider the relation schema ABD, ifwe have the FD's AB+D,D>B ‘Then ABD is not in BCNF because D is not a key. If we try to decompose it, however, we can't preserve the dependency ABD. GATE Previous Years Solved Papers: (@] | MADEEAsy 2.50 Which of the above statements is/are correct? @) Tonly () Neither I nor It (© BothIandII — @ Tonly [2019:2 Marks} Consider a relational table R that is in 3NF, but not in BCNF. Which one of the following statements is TRUE? 3 @ Rhas a non-trivial functional dependency X + A,where X isnot asuperkey and Ais, aprime attribute R has a non-trivial functional dependeney XA, where X is not a superkey and Aisa non-prime attribute and X is not a proper subset of any key. Rhas a non-trivial functional dependency X—A, where X is not a superkey and Aisa non-prime attribute and X isa proper subset of some key. A.cell in R holds a set instead of an atomic value. o) o @ [2020 :2 Marks} (a) Relation scheme R(A, B, C) has following functional dependencies: ABoC CoA ‘The candidate keys of relation scheme R(A, B, C)is {AB, BO} Functional dependency ABOC is allowed in both BCNF & 3NF per aey isa ‘set nie ks} A, EASY | Databases [sn Funetional dependency C54 Hereboth C & A are proper subset ofcandidate key. Therefore functional dependency C—>A is allowed in 3NF however, not allowed in BONF. ‘Therefore R is in 3NF but not in BONE, (b) The minimal keys of relation R are {AB, BC} (@) Relation Ra, b, c, d) has following functional dependencies: ate bod ‘The candidate key of relation Ris {ab} Attribute a & b are prime attribute whereas ¢ & dare non-prime attribute, Both the FD’s of Ris of kind “Proper subset of candidate key —> Non-prime attribute” Above typeof FD'sare not allowed in 2NF therefore, relation Ris in INF but notin 2NF. (@ Insertion into $ can cause inconsistency, since it, has foreign key which refers tothe primary key of, Deletion from R can cause inconsistency because it's primary key is the foreign key for S. - Ele ‘There is not always a decomposition into BCNF that is lossless and dependency preserving. So 3NFis considered adequate for normal relational database design, He = [Occupation|Pir] [Name] Age | Occupation| Category] ENG Doc SER Mus Pointers of index pointed to[1, 3,2, 5,4] records index key’ of index file always sorting sequence order (CON, DOC, ENG, SER, MUS] index entries pointed to [1, 3, 2, 5, 4] records respectively. Eso. (@) Rébid, Catalog, NameAuthor, NationalityAuthor) Primary key bid Because bid primary key {bid > Catalog NameAuthor, NationalityAuthor} Given relation in BCNF. () Two attributes BookTitle AuthorAddress + added torelation R(bid, Catalog, NameAuthor, NationalityAuthor, BookTitle, AuthorAddress) {bid + Catalog NameAuthor, NationalityAuthor, NameAuthor BooktTitle > bid catalog NationalityAuthor AuthorAddress} [First FD because of previous relation is 2" ED because of new primary key] Candidate keys [NameAuthor, BookTitle, bid, booktitle] Partial dependencies exists (Not in 2NF) Rel Rin INF. Eo We can choose the correct option by finding the closure ofeach option @ cD (CD)*={C, D, F} -. CDis not a key for R. ) O)*={A,B,C,D, EF} + BCisa key for. (© (B= (A,B, E 2 AB isnot a key for R @ AO*=1A,.B.CF 2 ACis nota key for R ‘Therefore, EC isa key for R, Be R=(STUV) S31,T3U,UsV,V58 Decomposed into R, and R, such that R, AR,= is lossy join decomposition which is not allowed in 2NF, 3NF, BCNF. 572 | GATE Previous Years Solved Papers | MADE (@) XY 2 is satisfied whereas Z > Y is not satisfied. () YZ+X& YZ both are satisfied (© YZ X is satisfied whereas X — Z is not satisfied (@ XZ > Y is not satisfied whereas Y > X is satisfied, Be R(A, B, C, D) R(AB) andR,(CD) F,=(A—B) and F,={C >D} All the original functional dependency can be derived from F, and F,, hence the decomposition is dependency preserving. The attribute B doesnot functionally determine either ‘A’ or‘C’ or‘D'. ‘The attribute D doesnot functionally determine either ‘A’ or ‘B’ or ‘C’. It is not lossless join (or it is lossy). go (® {AB, BCD} is BCNF decomposition is loseless join and dependency preserving. () {AB, BC, CD} is BCNF decomposition is loseless join and dependency preserving. (© {CAD, BC} is BCNF decomposition is Joseless join but not dependency preserving. (@ Given functional dependece is in BCNF. Degree of redundancy over functional dependencies (single valued FD's) is zero percent, He ‘The relation which is in BCNF is also in 3NF whereas the relation which is in 3NF may be or may not be in BCNF. Therefore, to make a guaranteed identification, BCNF definition should be used on the decomposition. Since given snapshot is only ari instance of the database, Just by checking the snapshot, we can't determine whether something is functional determined or not but on the contrary to this, we can correctly determine something which is not functionally determined. Age Bae B®) 219) Hence B does not functionally determine Ciis the correct answer. Relation (Roll number, Name, Date-of birth, Age) Fél’s which are the member ofthe relation (other FD’scan discard) Date-of-birth > Age Name— Roll number Roll_number > Name Candidate keys (Name, date-of-birth}, {Rollnumber, date-of birth} Date-of birth—> Ageis partial dependency which is not allowed in 2NF. Highest NF of given relation 1 NF. Student (mo, name, address) (mno} unique. Enroll (mo, eno, Cname) {rnocno} unique. Bach record of Enroll can be mapped one record of student based on natural join condition. So maximum 8 tuples in natural join and ro of Enroll foreign key references to student. So minimum also 8 tuples in natural join, Student (name, courseNo, rolino, grade) Rollno, CourseNo— grade Rollno, CourseNo—> grade Name rollno rollno name candidate keys {name, courseNo}, {rollno, CourseNo} Highest NF of given relation 3NF but not BCNF. Relation Empdtl (empcode, name, street, city, state, pincode) and functional dependency: empeode-> name, street, city, state, pincode pincode— state, city enter and street, city, state — pincode. Here candidate key is empeode. So, relation isin 2NF but pincode— state form non-prime to non prime which is not allowed in 3NF. Hence relation is in 2NF but not in 3NF. EASY | Databases Candidate key is F1, F2 in given relation. So, Fl > F3 and F2 — F4 forms partial dependency which is not allowed in 2NF. Hence relation is in INF only. Lossless join decomposition into BCNF always possible. But dependency preserving BCNF decomposition may not possible for all relations. ae = (A,B, C, D, E, H) FD={A>B, BC 3D, E >C,D>A} ‘The candidate keys of R is AEH, BEH, DEH because both of these generates the {A, B, C, D, E,H} Eo Apply membership test for all the given Funetional Dependencies. 1. CD AC CD* = CDEAB 2 BD CD BD*=BD i.e. BD cannot derive CD and hence is not implied. Similarly for rest two can be done. Be) 1er hy, ren ord So dof Relation r, contains 2000 tuples, and r, contains 2500 tuples. : ‘Maximum common R values are possible for join of r, and r, is 2000 i.e. equal to number of tuples in foreign key relation. Edw no, (vy = vYw (WYx)" = VYWXZ ra We have a dependencies ZY + V and WX, B + VYX, ZYX and WXY are candidate keys, => VXY is candidate key for R. isn | ea nm = © (AF)*={AFED} but given once (AR)*=(ACDEFG} which is wrong, @ (AB)*={ABCDG} but given (AB)*={ACDFG} which is wrong. | 373 ‘Statement (4) is false because in BCNF relation a prime attribute can't be transitively dependent onakey, zy @ IfA++Band AC then ABC not valid Gi) If A+B and AC then A-BC, therefore A~~BC is also valid. (ii) It A-+—BC and AB, then AC not valid (iv) If A+BC and A~B then AC, therefore A+ also valid. Every FD can replace as multi-valued dependency and multi valued dependency not allowed to split, Ele RABOD) BABGD) AS5Bc,c50,0-00) | kB B-9CC50,0-45) (88 86, Bo} RAB, Ry, RyBD) AB) | R480] BYRD, \ / asB| pac] Bop y cap | Dae Bi ay for Ry aes se PDs tesbreations (aR) is key for RyRy, Ry Ry Losses join decom "very FD and implied in sub relations Dependency preserving aecomposton Not in 2NF because here candidate key is ABand in FD’s proper subset of C.K. determine the non prime attribute ie. B> G. Blo book (title, author, catalogno, publisher, year, price) {file author + catalogno} catalogno — title author publisher year publisher title year price} Candidate keys {title author, catalogno} book isin 2NF between not 3NF Collection (title author catalogno) {title author catalogno catalog — title author} candidate keys {title author, catalogno} collection is in BCNF so also in 3NF. 574 | Ee B- Awhere R(A, B, C) and $(B, D, B) Asc Reontains 200 tuples Scontains 100 tuples Natural join pe =R oa S=z{6 (Rx S)] R=200 tuples and $= 100 tuples. Roa $= 100 [common in both or we can say Distinet equality between all common Attribute] Eo BankAccount_Num ean not be a key, because if students has only joint accounts then it can not identify uniquely. Ele BCNF is more restrictive than 3NF. A relation isin BCNFiff X > Y where ‘X’is super key and in 3NF iff other ‘X’ is super key or ‘Y' is prime attribute. :. Every relation in BNF is also in 3NF. Relation contain 8 attributes ABCDEFGH F= (CH > G, A BC, B> CFH, E> A, F>EG} Candidate key: AD, ED, BD, FD (a) Option (a) is correct because partial dependencies exist in functional dependency. |) : {E, F, H} > {E, FH, G, 1, J, K, L, M,N} .. EFHisa key for the relation R. Ege $1: False because check assertion meant for to specify given attribute valuesin specificrange GATE Previous Years Solved Papers : | MADE Easy, ‘and notallowed null, Foreign key constraint meant for attribute values should belongs to referenced key values and allowed null’s, ‘S2: False R(ABC) AB primary key S(ADE) — D primary key ‘A’ foreign key references to R not allowed because referenced key two attributes AB so that foreign key also must be two attributes. ) 1: Every two attribute relation is BCNF Sistrue $2: FD= {AB C, D> E, ABE, EC} {AB C, D> E, E> Gis nota minimal cover. ABean not determine B. $1 is TRUE and $2 is FALSE A sol. Super keys: (E, EF, EG, EH, EFG, EFH, EGH, EFGH} By sol. (StudentName, StudentAge) isa key Shankar X Shankar 19 ao Aprime attribute is an attribute that appears in some candidate key of given relation R. o), PS-3S is trivial FD, because {P, S} 2 (S}. ae In VWXZ, no complete candidate key exists. So, it is not super key. Bam Journal (Volume, Number, Startpage, Endpage, Title, Year, Price) Primary key: Volume, Number, Startpage, Endpage FD's: Volume Number Startpage Endpage > Title Volume number + Year | here X should not be 19 HEASY | Databases Volume Number, Startpage Endpage -> Price Given relation INF but not 2NF. This DB is redesigned following schemas R,(Volume, Number Startpage Endpage Title Price) which has FD's ‘Volume Number, Startpage Endpage — Title Volume Number Startpage Endpage — Price Which is in BONF. R,(Volume, Number, Year) Volume Number — Year Which is also in BCNF, Journal in INF R,R, in BONF Weakest NF which satisfy R, and R, and fails for journal is 2NF. see ver. WoW WX, YoVYSX Yo} W extraneous from VW — X V5WVOXYSVYSK YS Y X is redundant FD from above set 3H} WoW, V 5X, Y5V, ¥ 2} is minimal cover. I. en eke set al delet tl ca updatecseade = @ R/o 2 [2 z ] 2 “a Sa 8 | aol 7/3 3 | 2 5 | 38 9 | 7 6 | 9 5 | 7 8 | 5 7 | 2 5 s fs ‘Noother record need to delete because of deletion ists, of (, 8) record from vage, rage, page | 375 B® Schema II: Registration (rollno, courseid, email) Primary key [rollno, courseid] ‘Non-trivial functional dependencies: {rollno, courseid > email email > rollno} candidate keys {rollno, courseid}, {email courseid } Given relation is in 3NF but not in BCNF. 1219 X(PQRS) {QR 8, RP, S > Q} decomposed into YR) ZQRS) RP} QR>S,83Q Candidate key: R Candidate key: QR, RS Relation Y in BCNF Relation Z in 3NF but not BCNF Common attribute between Y and Z relations is R which is key for relation Y. So that given decomposition is lossless join decomposition. RoPiny QRo8 saq and dependency preserving decomposition. Ee R(A, B,C, D, B) Key: ABC, BCD ] sein FD: BOD : 9 is not super key and ‘8s prime attribute. Structured Query Language (SQL) 3.1 Suppose we have a database consisting of the following three relations. FREQUENTS (student, parlor) giving the parlors each student visits. SERVES (parlor, ice-cream) indicating what kind of ice-creams each parlor serves. LIKES (student, ice-cream) indicating what ice- creams each student likes (Assume that each student likes at least one ice- ‘cream and frequents at least one parlor) Express the following in SQL: Print the students that frequent at least one parlor that serves some icecream that they like. [1998 :2 Marks} 3.2. Which of the following is/are correct?” (@) An SQL query automatically eliminates duplicates (b) An SQL query will not work if there are no indexes on the relations (© SQL permits attribute names to be repeated inthe same relation (@ None ofthe above [1999:2 Marks} 3.8 Consider the set of relations EMP (Employee-no, Dept-no, Employee-name, Salary) DEPT (Dept-no, Dept-name, Location) Write an SQL query to: (a) Find all employee names who work in departments located at ‘Calcutta’ and whose salary is greater than Rs.50,000. () Calculate, for each department number, the number of employees with a salary greater than Rs.1,00,000. [1999: 2 Marks] 34. In SQL, relations can contain null values, and comparisons with null values are treated as unknown. Suppose all comparisons with a null value are treated as false, Which ofthe following pairs is not equivalent? 36 37 @) x=5, not (not (x=5)) () x=5,x> 4 and x <6, where xis an integ (0 x#5, not (x=5) (@ None ofthe above [2000:2 Marl iven relations r(w, x) and s(y, 2), the result of select distinet w, x from r,s is guaranteed to be same as r, provided (@) rhas no duplicates and sis non-empty (0) rand shave no duplicates (©) shasno duplicates and ris non-empty (@ rand shave the same number of tuples [2000: 2 Marks} Consider the following SQL query select distinct ay, a from ry, where p For an arbitrary predicate p, this query is equivalent to which of the following relational algebra expressions? (@) M60, Xm KR) ©) TL, 60 OSH Pd PD) © O96 082 Yoo ta) TG, 0%, 0-0 %q) {2003 :1 Mark] Consider the set of relations shown below and the SQL query that follow: Students: (Roll_number, Name, Date_of birth) Courses: (Course_number, Course_name, Instructor) Grades: (Roll_number, Course_number, Grade) select distinct Name from Students, Courses, Grades where ‘Students Roll_number=Grades.Roll_number SY | Databases | 577 and Courses.Instructor=Korth and ‘Courses. Course_number= Grades.Course_number and Grades. grade=A Which of the following sets is computed by the above query? (@) Names of students who have got an A grade in all courses taught by Korth (©) Names of students who have got an A grade inall eourses (© Name of students who have got an A grade in atleast one ofthe courses taught by Korth @ None of the above [2003 :2 Marks] ‘The employee information in a company is stored in the relation Employee (name, sex, salary, deptName) Consider the following SQL query select deptName from Employee where sex ="M’ group by deptName having avg (salary)> (elect avg (salary) from Employee) Itreturns the names ofthe department in which (@) the average salary is more than the average salary in the company ©) the average salary of male employees is more than the average salary ofall male employees ‘inthe company (©) the average salary of male employees is more than the average salary of employees in the same department, (@ the average salary of male employees is more than the average salary in the company (2004: 2 Marks} Arelational database contains two tables student and department in which student table has columns roll_no, name and dept_id and department table has columns dept_id and dept_name. The following insert statements were executed successfully to populate the empty tables: Insert into department values (1, Mathematics) Insert into department values (2, Physics) Insert into student values (1, ‘Navin’, 1) Insert into student values (2, Mukesh, 2) 3.10 31 Insert into student values (3, ‘Gita’, 1) How many rows and columns will be retrieved by the following SQL statement? Select * from student, department (a) 0 row and 4 columns (&) 3 rows and 4 columns (© 3 rows and 5 columns (@ 6 rows and 5 columns [2004 : 2 Marks} A table TI in a relational database has the following rows and columns: roll no. marks 1 10 2 20 3 30 4 Null The following sequence of SQL statements was successfully executed on table TI. Update TI set marks = marks +5 Select avg(marks) from TL ‘What is the output of the select statement? (@) 18.75 © 2» OB @ Null [2004 : 2 Marks} Consider two tables in a relational database with columns and rows as follows: ‘Table : Student Rollno Name _Dept_id 1 ABC 1 2 DEF 1 3 GHI 2 4 JKL 3 Table : Department Dept_id — Dept_name 1 A 2 B 3 c Roll_no is the primary key of the Student table, Dept_id is the primary key of the Department table and Student.Dept_id is a foreign key from DepartmentDept_id What will happen if we try to execute the following two SQL statements? (update Student set Dept_ic Roll_no =1 Gi) update Department set Dept_id=Null where Dept_id = 1 = Null where 578 | Bz 313 GATE Previous Years Solved Papers (@) Both (i) and (i) will fail () will fail but (i) will succeed (© @ will succeed but (i) will fail (@ Both (i) and (i) will succeed [2004 : 2 Marks] ‘A-company maintains records of sales made by its salespersons and pays them commission based on each individual's total sales made in a year. ‘This data is maintained in a table with following schema: salesinfo= (salespersonid, ttalsales, commission) Inacertain year, due to better business results, the company decides to further reward its salespersons by enhancing the commission paid to them as per the following formula: Tfeommission <= 50000, enhance it by 2% £50000 < commission <= 100000, enhance it by 4% fcommission > 100000, enhance it by 6% ‘The IT staff has written three different SQL scripts to calculate enhancement for each slab, each of these scripts is to run as a separate transaction as follows: TL Update salesinfo Set commission = commission * 1.02 Where commission < = 50000; T2 Update salesinfo Set commission = commission * 1.04 Where commission > 50000 and commission is < = 100000; TS Update salesingo . Set commission = commission * 1,06 Where commission > 100000; Which of the following options of running these transactions will update the commission of all salespersons correctly? (a) Execute 71 followed by T2 followed by T3 () Execute 2, followed by T3; Tl running concurrently throughout © Execute 73 followed by 12; TI r. ing concurrently throughout * (@ Execute 73 followed by T2f 1 [2005: s| In an inventory management system implemented ata trading corporation, there are several tables designed to hold all the information. Amongst these, the following two tables h information on which items are supplied by w suppliers, and which warehouse keeps whiel items along with the stock-level of these items, Supply = Inventory For a specific information required by ¢ management, following SQL query has been written Select distinct STMP.supplierid From Supply as STMP Where not unique (Select ITMP.supplierid From Inventory, Supply as ITMP Where STMP.supplierid = ITMP.supplierid ‘And ITMP.itemcode = Inventory itemeode supplierid,itemcode) ftemcode, warehouse, stocklevel) ‘And Inventory. warehouse =‘Nagpur’); For the warehouse at Nagpur, this query will find all suppliers who (@ do not supply any item (©) supply exactly one item (© supply one or more items (@ supply two or more items [2005 : 2 Marks} 3.14 Therelation book (title, price) contains the titles and prices of different books. Assuming that no two books have the same price, what does the following SQL. select title from book as B where (select count (*) from book as'T where'T. price > B. Price) <5 (a) Titles of the four most expensive books (b) Title ofthe fifth most iriexpensive book (© Title of the fifth most expensive book (@ Titles ofthe five most expensive books [2005 : 2 Marks} Directions for Question 3.15 to 8.16: Consider a database with three relation instances shown = below. The primary keys for the Drivers and Cars relation are did and cid respectively and the records. are stored in ascending order of these primary keys as given in the tables, No indexing is available in the database, EASY | Databases | 579 D : Drivers relation did dname rating age 2 Karthikeyan 7 Pe 9 Salman 1 33 31 Boris 8 55 2 Amolat 8 % 58 Schumacher 10 6 Sachin 1 3 a Senna 10 16 m4 Sachin 9 35 % Rahul 3 % 9% Ralph 3 88 R: Reserves relation did cid day 2 101 10/10/06. 2 102 10/10/06 2 103 08/10/06 2 104 o7n10106 31 102 10/11/06. 31 103 06/11/06 31 104 12/106 64 101 05/09/06 6 102 08/09/06 m4 103 08/09/06, C : Cars relation cid cname colour 101 Renault blue 102 Renault red 103 Ferrari green 104 Jaguar red What is the output of the following SQL query? select D.dname from Drivers D where D.did in ( select R.did from Cars C, Reserves R where R.cid=C.cid and C.colour = ‘red! intersect select R.did from Cars C, Reserves R where R.cid=C.cid and C,colour= ‘green’ ) (@) Karthikeyan, Boris (®) Sachin, Salman (©) Karthikeyan, Boris, Sachin (@ Schumacher, Senna [2006 : 2 Marks] 3.16 317 3.18 Let n be the number of comparisons performed when the above SQL query is optimally executed, If linear search is used to locate a tuple in a relation using primary key, then n lies in the range (a) 36 - 40 ) 44-48 (©) 60-64 (@ 100-104 [2006 : 2 Marks] Consider the relation account (customer, balance) where customer is a primary key and there are nonnull values. We would like to rank customers according to decreasing balance, The customer with the largest balance gets rank 1. Ties are not broken but ranks are skipped: if exactly two customers have the largest balance they each get rank 1 and rank 2 is not assigned. Query 1: Select A.customer, count (B.customer) from account A, account B where balance <= B.balance Group by A.customer Query 2: Select A.customer, 1 + count (B.customer) from account A, account B where Avbalance =esalary) Select. empld Fromemployeee Where e.salary> Any (Gelect distinct salary From employee s ‘Wheres department =5") (@) Q, isthe correct query ©) Quis the correct query (© Both Q, and Q, produce the same answer @ Neither Q, nor Qy is the correct query [2007:2 Marks) Directions for Question 3,20 to 3.21: Consider the following relational schema: Student (school-id, sch-roll-no, snamo, saddress) School (school id, sch-name, sch-address, sch-phone) Enrolment(school-id sch-roll-no, erollno examname) BxamResult (erollno, examname, marks) GATE Previous Years Solved Papers 3.20 321 3.22 |_ MADE Easy. ‘What does the following SQL query output? SELECT sch-name, COUNT (*) FROM — School C, Enrolment E, ExamResult R E,school-id C.school-id AND E.examname = Rexamname AND E.Erollno = Rerollno AND R.marks = 100 AND S.school-id IN (SELECT school-id FROM student GROUP BY school-id HAVING COUNT (*) > 200) GROUP By school-id (@) for each school with more than 200 students appearing in exams, the name of the school and the number of 100s scored by its students for each school with more than 200 students init, the name of the school and the number of 100s scored by its students for each school with more than 200 students init, the name of the school and the number of its students scoring 100 in at least one exam (@ nothing; the query has a syntax error {2008 : 2 Marks] WHERE o oO Consider the following tuple relational calculus query. {tI3E ¢ Enrolment t = E.school-id « |{x1x Enrolmentax.school-id= tAGB ExamResult Beerollno = x.erollno ~ B.examname = x.examname a B.marks > 35)}| + I(xlx Enrolment a x.school-id = t}|* 100> 35} Ifa student needs to score more than 35 marks to pass an exam, what does the query return’? (@) The empty set () schools with more than 35% of its students enrolled in some exam or the other (0) schools with a pass percentage above 35% over all exams taken together @ schools with a pass percentage above 35% over each exam [2008 : 2 Marks] Consider a database table T containing two columns X and Y each of type integer. After the creation of the table, one record (X= 1, Y= 1) is inserted in the table. DEEASY | Databases | 581 Let MX and MY denote the respective maximum. values of X and ¥ among all records in the table at any point in time. Using MX and MY, new records are inserted in the table 128 times with X and Y values being MX +1, 2’MY + I respectively. Ttmay be noted that each time after the insertion, values of MX and MY change. ‘What will be the output of the following SQL ‘query after the steps mentioned above are carried out? SELECT Y FROM'T WHERE X = 7; (@ 127 () 255 © 29 @ 257 [2011:2 Marks] Database table by name Loan_Records is given below: Borrower | Bank Manager | Loan Amount Ramesh [Sunderajan | 10000.00 ‘Suresh | Ramgopal 5000.00 Mahesh [Sunderajan | 7000.00 What is the output of the following SQL query? SELECT count(+) FROM ( (SELECT Borrower, Bank Manager FROM Loan_Records) AS $ NATURAL JOIN (SELECT Bank Manager, Loan_Amount FROM Loan Records) AS'T 9 @6 . [2011:2 Marks} Which of the following statements are TRUE about an SQL query? P: An SQL query can contain a HAVING clause even ifit does not have a GROUP BY clause Q: An SQL query can contain a HAVING clause only ifit has a GROUP BY clause R:: Allattributes used in the GROUP BY clause must appear in the SELECT clause S : Not all attributes used in the GROUP BY clause need to appear in the SELECT clause (@ PandR (b) PandS © QandR @ Qands [2012: 1 Mark] Common Data for Que: ns 3.25 and 8.26 Consider the following relations A, B and C: 3.25 3.26 327 A 1a ‘Age 2 [Ann | 00 1s | Seya | 26 99 | Robt [1 Name B. a ‘Age 15_| Shreya | 24 2s | Hai | 40 ‘Name 98 | Rott | 20 99 | Ronit [at c 1a | Phone | Age 10 | 2200 | a 99 | 2100 | or How many tuples does the result of the following relational algebra expression contain? Assume that the schema of AU Bis the same as that of A. (AUB) Pd araswove.ttcas © 4 @9 @7 Os [2012:2 Marks} How many tuples does the result of the following SQL query contain? SELECT Ald FROMA WHERE A.Age> All (SELECT BAge FROMB WHERE BName='Arun) b) 3 @1 @4 oo [2012:2 Marks} Given the following schema: employees(emp-id, first-name, last-name, hire-date, dept-id, salary) departments(dept-id, dept-name, manager-id, location-id) ‘You want to display the last names and hire dates ofall latest hires in their respective departments in the location ID 1700. You issue the following query: 582 | 3.28 3.29 3.30 SQL > SELECT last-name, hire-date FROM employees WHERE (dept id, hire-date) IN (SELECT deptid, MAX(hire-date) FROM employees JOIN departments USING (dept-id) WHERE location-id = 1700 GROUP BY dept-id); What is the outcome? (@) It executes but does not give the correct result () Itexecutes and gives the correct result (0 It generates an error because of pairwise comparison. (@ It generates an error because the GROUP BY clause cannot be used with table joins in asubquery. [2014 (Set-1) :2 Marks] SQL allows duplicate tuples in relations, and correspondingly defines the multiplicity of tuples in result of joins. Which one of the following queries always gives the same answer as the nested query shown below: select * from R where a in (select S.a from S) (@) select B.* from R, S where R.a=S.a () select distinct R.* from R,S where R.a=S.a (0 select R.* from R(select distinct a from S) as$1 where Ra=SLa select R.* from R,S where R.a = S.a and is uniqueR : [2014 (Set-2) :2 Marks) @ Whatis the optimized version of the relation algebra expression X(t (6p, (6,,())), Where Al, Aare ‘sets of attributes in r with Al c A2 and F1,F2 are Boolean expressions based on the attributes in r? ©) RCpireg?) © Rui prve9( © RaCpinr) @ FulGperr) [2014 (Set-3) : 1 Mark] Consider the following relational schema: employee(empld, empName,empDept) customer(custld, ‘custName,salesRepld,rating) salesRepld is a foreign key referring to empld of the employee relation. Assume that each ‘employee makes a sale to at least one customer. GATE Previous Years Solved Papers 331 3.92 | MADE Easy What does the following query return? SELECT empName FROMemployee E WHERE NOT EXISTS (SELECT custld FROMeustomerC WHERE C.salesRepld = E.empld AND Crating >'GOOD); (@) Names ofall the employees with at least one of their customers having a ‘GOOD’ rating, () Names of all the employees with at most one of their customers having a‘GOOD rating, (0 Names ofall the employees with none oftheir customers having ‘GOOD rating. (@ Names of all the employees with all their customers having ‘GOOD rating. [2014 (Set-3): 2 Marks} Consider the following relations: ‘Student Performance TeiLNo [Suden Ware] [RON [ Course | Mat 1 | Ral + | Man [80 2 [Rott + _[enaisn [70 3 | Ral 2] mam [75 3__[ Enaisn | 20 2_| Physics | 65 3_[ man [0 Consider the following SQL query. SELECTS. Student_Name, sum (P.Marks) FROM Student S, Performance P WHERES. Roll No=P-Roll_No GROUP BYS.Student_Name ‘The number of rows that will be returned by the SQL query is [2015 (Set-1) :2 Marks] SELECT operation in SQLs equivalent to (@) the selection operation in relational algebra (0) the selection operation in relational algebra, except that SELECT in SQL retains duplicates the projection operation in relational algebra the projection operation in relational algebra, except that SELECT in SQL retains duplicates © @ [2015 (Set-1) :1 Mark] EASY | Databases Consider the following relation: Cinema (theater, address, capacity) Which of the following options will be needed at the end of the SQL query SELECT PLaddress FROM Cinema P1 such thatiit always finds the addresses of theaters with maximum capacity? (@) WHERE Plcapacity > = All (select P2 capacity from Cinema P2) (©) WHERE PI capacity > capacity from Cinema P2) (©) WHERE Pl capacity > All (select max (P2. capacity) from Cinema P2) (@ WHERE P1capacity > Any (select max (P2. capacity) from Cinema P2) [2015 (Set-3) :1 Mark] Any (select P2. Consider the following database table named. water_schemes: [scheme_no |district_name|eapacity 1 ‘Ajmer 20 1 Bikaner 10 2 Bikaner 10 r 3 Bikaner 20 1 Churu 10 2 Chura 20 1 Dungergarh | + 10 the number of tuples returned by the following SQL query is rks} with total (name, capacity) as select district_name, sum (capacity) from water schemes ED group by district_name oo, with total_avg (capacity) as ae select avg (capacity) from total Es select name 2bra, from total, total_avg ains where total.capacity > total_avg. capacity [2016 (Set-2): 2 Marks} 3.35 Consider a database that has the relation schema EMP (Empld, EmpName, and DeptName). An instance of the schema EMP and a SQL query on it are given below: EMP. Empld | EmpName [DeptName 1_[_Xx¥A AA 2 | xB AA 3_[_ xe AA 4 | xD AA 5 XYE AB 6 XYF AB 7 | xe AB 8 |_XxYH aC 9 Xv aC i0_| xy AC n | XK ‘AD | XY. AD 13_[_x¥M AE SELECT AVGEC.Num) FROM EC WHERE (DeptName, Num) IN (SELECT DeptName, COUNT(Empld) AS BC(DeptName, Num) FROM EMP GROUP BY DeptName) ‘The output of executing the SQL query is [2017 (Set-1): 1 Mark] 3.36 Consider the following database table named top_scorer. top_scorer player country goals Klose Germany 16 Ronaldo Brazil 15 GMuller | Germany u Fontaine France 18 Pele Brazil 2 Klinsmann | Germany u Kocsis Hungary u Batistuta | Argentina 10 Cubillas Peru 10 Lato Poland 10 Lineker England 10 TMuller Germany 10 Rahn Germany 10 Consider the following SQL query: 3.37 3.38 SELECT ta.player FROM top_scorer AS ta WHERE ta.goals > ALL (SELECT tb.goals FROM top_scorer AS tb WHERE tb.country = ‘Spain) ANY (SELECT te.goals FROM top_scorer AS te WHERE te.country = ‘Germany)) AND ta.goals > ‘The number of tuples returned by the above SQL query is [2017 (Set-2):2 Marks] Consider the following two tables and four queries in SQL. Book (isbn, bname), Stock (isbn, copies) SELECT Bisbn, S.copies FROM Book BINNER JOIN Stock S ON Biisbn = S.isbn; SELECT B.isbn, S.copies FROM Book BLEFT OUTER JOIN Stock S ON Bisbn = S.isbn; SELECT B.isbn, S.copies FROM Book BRIGHT OUTER JOIN Stock $ ON Bisbn = S.isbn; SELECT B.isbn, S.copies FROM Book B FULL OUTER JOIN Stock $ ON Bisbn = S.isbn; Which one of the queries above is certain to have an output that is superset of the outputs of the other three queries? (@) Query 1 © Query3 Query 1: Query 2: Query 3: Query 4: ©) Query 2 @ Query4 (2018: 1 Mark] Arelational database contains two tables Student and Performance as shown below: ‘Student Roll_no. | Student_name 1 Amit 2 Priya 3 Vint 4 Rohan 5 ‘Smita GATE Previous Years Solved Papers Performance Rollno. | Student.code | Marks: 1 A % 1 8 95 1 ce 0 2 aA oo 2 ce 3 c ‘The primary key of the Student table is Roll_no, Forthe Performance table, the columns Roll_no, ‘and Subject_ode together from the primary key, Consider the SQL query given below: SELECTS Student_name, sum(P.Marks) FROM Student S, Performance P WHERE P. Marks > 84 GROUP BY Student_name; ‘The number of rows returned by the above SQL query is [2019:2 Marks} 3.39 Consider a relational database containing the following schemas. Catalog Supplies ‘ao | pro | cost | [sno] name Tecation st | Pt | 190 | | st[MsRoyalfumtue | Deh S| Pe | 80 | | St[MsBalaj mitre | Bangalore St | 3 | 100 | | 88] Mis Premium furitre] Chena 2 | ps | 200 sz | 5 | 250 Parts so [pt | 250 | | Bae] sname: [part spec: seb pe Taso] |_Pt_| Table | Wood eee poe] (P| one | ems se bee | aso | | P2 | Tee | Sto! Pa | Amirah | Stee! S| Amiran | Wood ‘The primary key of each table is indicated by underlining the constituent fields. SELECT s.sno, s.name FROM Suppliers s, Cataloguee WHERE 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 (a) 2 (b) 5 @4 @o z [2020:1 Mark] 34 ©) 313 @) 322 @) 332 @ 35 @) a4 @ 3.23. (c) 3.83 (a) 36 (a) 3.15 (a) B24 (c) 337 @ 37 © 3.16 ©) 3.25 (@) 3.39 (©) Structured Query Language (SQL) Student FREQUENTS parlor in (select parlor from SERVES where ice-cream in (select ice-cream from LIKES where LIKES.student = FREQEUNTS.student)) arks) SQL rks} athe (a) To eliminate duplicate rows, we need to use “DISTNICT” keyword with SELECT in SQL query. SQL not permits attribute names tobe repeated in the same relation. Therefore option (d) is correct. Employee-name EMP Salary > 50,000 and Dept-noin (Select Dept-no from Dept where Location ="Caleutta’) or EMP. Employee-name EMP, DEPT EMP. Dept-no=DEPT.Dept-no and DEPT.Location="Caleutta’ and EMP Salary > 50,000 Dept-no, count (Employee-no) EMP Salary> 1,00,000 group by Dept-no. . Select, SQ Comparison with Null treated as falsei.e. null =5 false null #5 false null <5 false Ree AD CIN 38 @ 39 @) 310 © 311 @ 3.17 (c) 3.18 (b) 3.19 (b) 3.20 (d) 3.26 (b) 3.27 (b) 328 (@) 329 (@) Given expression: (a) X=5 not(not(X = 5)) (alse of X is null) (false of Xis null) both are equal even X is null. @) X=5 X>4andX<6 (alse of Xis null) (false of Xis null) both are equal even X is null. ( X45 not(X=65)) (false of Xis mull) (true of Xis null) both are equal even X is null. So that these expressions are not equal of X is null and comparison with X treated as false. He Ifany of the relation is empty in cross-join then the overall result is empty. Therefore S need to be non-empty. To have same rows of then’ should not have duplicates. me ‘The given SQLis Select distinet ay, ayy 4 8, from ry, ty where P All possible combination of tuples from r,t», is denoted by r, x1 x... X 1, IfPisa predicate then to select the all, condition is denoted by a (r, XxX... 14) If we wants to select only some tuples in the relation then composite expression for above SQLis Tol Xt X tq) ‘There are three relations Select distinct name, select the name of students and then there are three predicates Courses, instructor = korth specify the courses taught by Korth, The other two predicates specify that studentcan eama grade at least A from courses sothe SQL query compute. ‘Name of students who have got an A grade in at Jeast one ofthe courses taught by korth. me Select deptName from employee where sex='M" grouply deptName having avg (salary) (select avg (salary) a (Avg ualary of ale employees > from employees) ‘seach departs] renin nt compa It returns the names of departments in which the average salary of male employeesiis more than the average salary in the company. i ‘There is no specific joining condition specified, soit will retrieve Cartesian product of the tables. Number of rows = Product of number of rows in each relation = 3 * 2= 6 Number of columns=Sum of number of columns =3+25=5. eo Update on null gives null Average function ignores null values. So, Average will produce (15 + 25 + 35)/3 = 25, , si Foreign key Student Department [Rollno | Name [Dept.i [Dept id | Dept name| 1 | apc] 1 1 A 2 | per} 1 2 B a | om | 2 3 c 4 [om | is 1. Onexecute 1**SQL statement we try to put Null where Roll_no = 1, Since foreign key can contain Null. So allowed to update. 2. Onexecute 2 SQL statement we try to put ‘Null where Roll_no = 1, since primary key of department table, Hence cannot be Null. So it will fail to execute. GATE Previous Years Solved Papers : | MADE EASY Be Commission enhancement formula is: If commission < 50000, enhance it by 2%. 150000 100000, enhance it by 6%, If we execute T! first, then there may be case that amount less than equal to 50000 now comes ‘to range 50000 to 100000, now if we execute T2 we will get wrong output. So, first we need to evaluate T3 since all are increasing after calculation, then T2 then T1. Hence order will be T3 followed by T2 followed by Tl. Select ITMP supplierid From Inventory.Supply as ITMP Where STMP supplierid=ITMP.suppliered And ITMP.itemeode = Inventory.itemeode ‘And Inventory. warehouse = ‘Nagpur Inner query will give supplier id of supplier who supply atleast one item at ‘Nagpur’. Here if supplier supply more than 1 item then supplier id will be duplicated in result. ‘When outer query execute, then it will return’ distinct supplier id of those supplier who supplier atleast two item at Nagpur. Note: Not unique returns true for repeated values. Be Select ttle FROM book asB Where (Select count (*) FROM book as'T Where T.price > B.price) <5 Inner query counts number of books more price than B.price of count <6 then B.title in result if count 0 means no other book more price = most expensive count 1, 2, 3,4 more one, two three, four other ‘books more price = 2%, 3%, 45 most expensive Dooks. Query retrieves titles of fire most expensive books. price ultif most | 587 For color = “Red”, did = (22, 22, 31, 64} For color = “Green”, did = (22, 31, 74} Intersection of Red and Green will give={22, 31} which is Karthikeyan and Boris. -(@) Sub Query (Select Rdid From Cars C, Reserves R Where R.cid= C.cid and C.color=red) J Optimize Cars Reserves (R) comp. v color = red 2 comp, result 1120 records aid Reid= Ccid] 00mp, J [22 L st Raid 64 Gi) Sub Query elect R.did From Cars C, Reserves R Where R.cid=C.cid and C.color = green) 4 Optimize Cars © Reserves ®) 4eomp.| |ceotor= green oom. rent no record om Reid= Ceid] 10comp. J [22 n Ei (Gi) Intersection of sub query result: = Intersection can translate into inner join. = Minimum ‘6’ comparisons to get result of intersection result (22, 31] Gv) Retrieve driver name whose id in (22, 31] approximately. In also works as inner join 4 comparisons. ‘Total cost 24 + 14 +6 + 4= 48 (approximately) Query 1: () FROM Ace A, Ace B eid bal] [eid bal cr 30 30 cz 30 cz 30 cs cs 35 ca ce 35 5 20 5 20 515 815 (2) Where A.bal <=B.bal — Group by A.cid 1 30 C1 80 1 30 C2 80 c2 30 C1 30 cz 40 C2 a0 3 25 ci 30 3 25 C2 30 C3 25 03 25 03.258 C4 25 (A) Select A.cid count (Bid) result Query 1 wrong as per given specification. Query 2: () Fromace A, Ace B @) Where A.bal fe sisjslsisis Rohit Rohit s/s) ele] elals|5 10 99 | 2100 9 2 3 Inthis (select B. Age From B where B, Name= Arun) 4 4 So all A. Age will be selected, so Ans 3. Given SQL query will correctly display the last names and hire dates of all latest hires in their respective departments in the location ID 1700. ins Select * from R where a in (select s.a from S) Select R.* from R, (select distinct a from S) as Si where R.a= S1.a. Ble (9 43 (4400) = Hy, (X), since AI CAR (0p, (48))= 6p, 728) 2. May Mg Fpy Gp) = Ry Opp) He SELECT empName FROM employee E WHERE NOT EXISTS (SELECT Custla |FROM Customer C WHERE CSalesRepld |AND Crating <= 'GOOD' .empla| where, the SQL query in the box represents all customers having other than ‘good’ while the complete query represents name of all employees with all their customers having a ‘good rating’. Ese. Student Name] Marks Raj 310 Rohit 140 @) Tin relation algebra is similar to SELECT in SQL but the only difference is that ‘IT’ gives distinct rows by eliminating duplicates but SELECT does not remove duplicates, Ee ‘The following query finds the addresses of theaters with maximum capacity: SELECT P1.address FROM Cinema P1 WHERE P1 capacity> = All select P2. capacity from Cinema P2) ‘Total [Name] Capaciy | ie result of ‘Aimer 20 | fist query. Bikaner 40 Chura 30 Dungargarth | 10 590 | ‘Total average is result of, second subquery. Select name from Total, Total_Avg Where total capacity 2 Total_Avg capcity Query results 2 records. GATE Previous Years Solved Papers : | MADE EAsy WHERE ta.goals > ALL (SELECT tb.goals, FROM top_scorer as tb WHERE tb.country =‘Spain) AND tagoals > ANY (SELECT tegoals FROM top_scorer as te WHERE te.country ‘Germany) Number of tuples in result 7. EMP Book [RBH [mme] Stock [a [ema Empld | EmpName | DeptName 2 | A +} ie WA > 7/3 6 | 200 aE] a ¢ fe 10 | 200 37 xve ry @ [> 2» | «00 + [ xvD | AA pone 5 | We AB query: aba [eopan] Query 2: 6 | XP 3B aalioo 7 | x¥G | AB aul Esoo 8 XYH AC 10 | 200 9 | x AC 70 | XW AC t | _X¥K_| AD | _xYL AD query : [bm Si] Query «(aba [aa 13 [_XYM AE aa ame EZ) | 200 6 | 20 SELECT AVGECNum 10 | 200 10 | 200 FROM EC WHERE (DeptName, Num) IN| (GELECT DeptName, COUNT(Empld) AS BO( DeptName, Num) FROM EMP GROUP BY DeptName) Result of inner query BC[ Dept name [Number AA 4 AB 3 AC 3 AD 2 AE T Result of outer query : 2 Select ta.player FROM top_scorer as ta 12 | 400 2 | Null 8 | Null 12 | 400 Query 4 is full outer join so that full order record set superset of records compare to inner join, left outer join and right outer join. ‘Student Performance Rollo. | Student name Roll_ne| Student_code | Mars 1 ‘Nt 1 nN 28 2 Piya 1 8 % 3 wet | X [4 c * ‘ Rohan 2 A 2 5 ‘Smita 2 ce 2 3 c 0 In where condition no condition over Roll_no so query produces all groups. ‘Total 5 different student names all 5 group records in result, EASY | Databases [591 SELECT S.sno, S.sname FROM Supplier S, catalog C WHERE S.sno=C.sno AND cost> (SELECT AVG (cost) FROM Catalog WHERE pno='P4 GroupBy pno); 160 Catalog = 7 me) | \ fi = 4 Ps Pi 2 5 Pe alk glelg B28 205 250 Ba/s [2|e|e]e|ele|e|ele se | BF 33 [PF so | PF ~ 4 rows in table, 0 Relational Model: Relational — Algebra and Tuple Calculus 4 42 43 44 45 ‘Aninstance ofa relational scheme R(A, B, C) has distinct values for attributes A. Can you conclude that Aisa candidate key for R? [19941 Mark] Give a relational algebra expression using only the minimum number of operators from {U,—} is equivalent toRS. [19941 Mark] A library relational database system uses the following schema USERS (User#, UserName, HomeTown) BOOK (Book #, BookTitle, AuthorName) ISSUED (Book #, User #, Date) Explain in one English sentence, what each of the following relational algebra queries is designed to determine. © pte vn patie (USERS >< ISSUED) », U,9,—)? {@) Department address of every employee (b) Employees whose name is the same as their department name (0 The sum ofall employees salaries @ Allemployees ofa given department (2000: 1 Mark] Which of the following relational calculus expressions is not safe? (@) {tue R, (1A) = ulAl) 735 € Ry (Al =s{AD)} () {t|'Vue R, (ufA] ="x" => 3se R, (tlA] = fA] asfA]=ulAD))} @ tl te RY @ {tl3ue R, ((A}=ulAl) nse R, CHA]=slAD} [2001:2 Marks] With regard to the expressive power ofthe formal relational query languages, which of the following statements is true? (@) Relational algebra is more powerful than relational calculus (b) Relational algebra has the same power as relational calculus (© Relational algebra has the same power as safe relational calculus (@ None ofthe above [2002 : 1 Mark] EEASY | Databases | 593 10 Let R,(A,B, ©) and R,(D, E) be two relation schema, where the primary keys are shown underlined, and let C be a foreign key in Ry referring to R,. Suppose there is no violation of the above referential integrity constraint in the corresponding relation instances, and r,, Which one of the following relational algebra expressions would necessarily produce an empty relation? @) Mp) ~ Mel) ©) Mo() ~My) © Mp(F, cp Ry) ~ Melts) @ Melt Pc-n Ra) [2004 : 1 Mark] 4.11 Consider the relation Student (name, sex, marks), where the primary key is shown underlined, pertaining to students in a class that has atleast cone boy and one girl. What does the following relational algebra expression produce? (Note: p is rename operator) Thgge(Cyxcemaie Student) ~My ygo(Student bo Poyxm(Student)) (oor foe» x= males marks = 75 and roll between 2000 and 3000; Relations Sand H with the same schema as those ofthese two tables respectively contain the same information as tuples. A new relation $' is obtained by the following relational algebra operation: Those (Gasott= sll Grarks> 7 andro 2000 and roit< 3000 (5) * (H)) ‘The difference between the number of rows output by the SQL statement and the number of tuples in Sis @6é 4 @2 @0 [2005 : 2 Marks) GATE Previous Years Solved Papers : | MADE EAsy 4.14, Which of the following relational query languages have the same expressive power? I. Relational algebra. IL Tuple relational calculus restricted to safe expressions. TIL Domain relational calculus restricted to safe expressions. (@) Mand only (© Vand II only ®) Tand Il only @ 1, Wand I [2006 : 1 Mark] 4,15 Consider the relation enrolled (student, course) in which (student, course) is the primary key, and the relation paid (student, amount) where student is the primary key. Assume no null values and no foreign keys or integrity constraints. Assume that amounts 6000, 7000, £8000, 9000 and 10000 were each paid by 20% of the students. Consider these query plans (Plan 1 on left, Plan 2 on right) to “list all courses taken by students who have paid more than x.” Enrolled Paid Enlai 1 4 t i ‘Probe ines | | Seen! | [Probe index | | Sequential cowie | [22% 0 | | Somat | | set \__/ \__f Tadexednestlony jin]— [Tadexed nested lop in i I Projet on ure Seles on amount > 7 I Free nar 7 A disk seek takes 4 ms.disk data transfer bandwidth is 300 MB/s and checking a'tuple to see if amountis greater than xtakes 10 ys. Which of the following statements is correct? (@) Plan 1 and Plan 2 will not output identical row sets for all databases &) Acourse may be listed more than once in the output of Plan 1 for some databases (© For x = 5000, Plan 1 executes faster than Plan 2 for all databases (@ For x = 9000, Plan 1 executes slower than Plan 2 for all databases ° [2006 : 2 Marks] 4.16 Consider a selection ofthe form 6 ¢ p(t), where risarelation with 1000 tuples. Assume that the attribute values for A among the tuples are uniformly distributed in the interval [0, 500]. 417 418 ‘Which one of the following options is the best estimate of the number of tuples returned by the given selection query? @ 50 © 10 (b) 100 @ 200 (2007 : 2 Marks} Consider the following relation schemas: b-Schema = (b-name, b-ity, assets) a-Schema = (a-num, b-name, bal) d-Schema = (cname, a-number) Letbranch, account and depositor be respectively instances of the above schemas. Assume that account and depositor relations are much bigger than the branch relation. Consider the following query: Thename Oncigrragat abaieo (PrANCH P< (account > depositor)) Which one ofthe following queries is the most efficient version of the above query? © Thine ia <0 re account) >< depositor) © Tesame Gpeity = rarar PFANCHES Opa) « 9 account >< depositor)) 0. Tee rey =rague PANCH Py ye -ageat sat co A€C0Unt P< depositor) @ Megane Opeiy=*agarbFANCH PS (Cy rye setareo acount Dt depositor)) [2007 : 2 Marks} Information about a collection of students is given by therelation studInfo (studld, name, sex). The relation enroll (studld, Courseld) gives which student has enrolled for (or taken) what course(s). Assume that every course is taken by at least ‘one male and at least one female student. What does the following relational algebra expression represent? Thocrata (Myaate Cr Thewt(enroll))~ enrol) (a) Courses in which all the female students are enrolled (©) Courses in which a proper subset of female students are enrolled (© Courses in which only male students are enrolled @ None of the above .(studInfo) * * female [2007:2 Marks} al \DEEASY | Databases | 595 419 Consider the relation employee (name, sex, supervisorName) with name as the key, supervisorName gives the name ofthe supervisor of the employee under consideration. What does the following Tuple Relational Calculus query produce? {e.name | employee (@) a (¥%) [employee (x) vx.supervisorName #ename v x.sex=“male"}} (@) Names of employees with a male supervisor (©) Names of employees with no immediate male subordinates (©) Namesofemployees with noimmediate female subordinates (@ Names of employees with a female supervisor [2007: 2 Marks] — 420 Let Rand Sbe tworelations with the following schema: R(P, Q, R1,R2, 3) S(P, Q 81,82) where {P, Q} is the key for both schemas. Which ofthe following queries are equivalent? L 1,Roa8) TL 11,(R) >a My(S) TIL M1y(Mpg R) AM g(S)) IV. Tp fIp.q R)~ Mpg) Tp g(S) (@) OnlyTandI (6) OnlyTand It © OnlyI, Manat @ Only, Hand IV (2008: 2 Marks} 421 LetRandSberelational schemes such that R= {a,b,c} and S= {c}. Now consider the following queries on the database Lm gC) stp s(t) *Stp gs) TL {tte s() AV ues@ ver(u=vis] at=vIR -S))} ILL titer, s() AV ver@ ues(u=vfs} at=vIR -§)} IV, Select R.a, Rb from R, $ where Re=S.c Which of the above queries are equivalent? (@) Land II @) Land II ( HandIV @ Mandlv (2009: 2 Marks} Common Data for Questions 4.22 and 4.23 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) 4.22 Consider the following relational query on the above database: SELECTS.sname FROM Suppliers WHERES. sid NOTIN (SELECT C.sid FROM Catalog C WHERE C pid NOTIN (SELECT P.pid FROM Parts P WHEREP.olor > 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 ofall 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 2009: 2 Marks} 4.23. Assume that, inthe suppliers relation above, each, supplier and each street within a city has a ‘unique name, and (sname, city) forms a candidate key. No other functional dependencies areimplied other than those implied by primary and candidate keys. Which one of the following is ‘TRUE about the above schema? (@) The schema is in BCNF (©) The schema is in 3NF but not in BCNF (© The schema is in 2NF but not in 3 NF @ The schema is not in 2NF [2009: 2 Marks] 4.24 Suppose R, (A, B) and R,(C, D) are two relation schemes. Let rl and r2 be the corresponding relation instances. Bis a foreign key that refers to Cin R2, Ifdata in rl and? satisfy referential integrity constraints, which of the following is ALWAYS TRUE? 596 | 425 4.26 @ Tye) Me) =6 ) Mla) =TIg(e) = © Mye)=Me,) @ Mg(r,)—Mo(r,) #0 [2012:2 Marks} Consider the following relational schema. Student (rollno: integer: sname string) Courses (courseno: integer, ename: string) Registration (rollno: integer, courseno: integer, percent: real) Which ofthe following queries are equivalent to this query in English? “Find the distinct names of all students who score more than 90% in the course numbered 107” 1. SELECTDISTINCTS.sname FROM Students as 8, Registration as R WHERE R-rollno=S.roll.no AND Rourseno=107 and R.percent>90_ THegame(Frourenn=107 apeventoo) Regis-tration bd Student)) {T | 38e Students, 3Re Registration (S.rollno=R.rollno « R.courseno=107 « Ropercent>90,T.sname=S.sname)} { | 3S,AR, ( € Student 0 < Sq 107,R,>€ Registration «Rp > 90)) @ ,1,1landIV () 1, land only (© LMandIVonly @) I,UlandIV only [2013:2 Marks} IL. W. Consider a join (relation algebra) between relations r(R) and s(S) using the nested loop method. There are 3 buffers each of size equal to disk block size, out of which one buffer is reserved for intermediate results. Assuming size(r(R)) < size(s(S)), the join will have fewer number of disk block accesses if (@ relation r(R) is in the outer loop. (®) relation s(S) is in the outer loop. (© join selection factor between r(R) and s(S) is more than 0.5. (@ join selection factor between r(R) and s(8) is, less than 0.5. [2014 (Set-2): 2 Marks] GATE Previous Years Solved Papers: (@] | MADEEAsy 427 428 429 Consider the relational schema given below, where eld of the dependent is a foreign key referring to empld of the relation employee, ‘Assume that every employee has at least one associated dependentin the dependent relation, employee(empld, empName, empAge) dependent (depld, eld, depName, depAge) Consider the following relational algebra query: Thue (€mployee) ~My, (employee Penpidectionptzecdopge) dependent) ‘The above query evaluates to the set of emplas of employees whose age is greater than that of (a) some dependent. () all dependents. (0) some ofhisher dependents. (@) allofhis/her dependents. 2014 (Set-3):2 Marks} Consider two relations R, (A, B) with the tuples (2, 5), (3, 7) and R,(A, C) = (1, 7), (4, 9). Assume that R(A,B,C) is the full natural outer join of R, and R,. Consider the following tuples of the form (A,B,C): a= (1,6, 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? (a) Reontains a,b, e, f, g but not c, d (&) Reontains all of a,b, ¢, de, fg (©) Reontainse, f, gbut not a, b @ Reontains e but not f, g [2015 (Set-2): 1 Mark] Consider a database that has therelation schemas EMP(Empld, EmpName, Deptid) and DEPT (DeptName, Deptid). Note that the Deptid can be permitted to be NULL in the relation EMP. Consider the following queries on the database expressed in tuple relational calculus. L_{t|3ue EMP(t{EmpName] = u[EmpName] aVve DEPT (t{Deptld] + vDeptld))} IL {t|3u¢ EMP(¢{EmpName] = u[EmpName] nave DEPT(t{Deptld] + viDeptld))} TL {t|3u ¢ EMP(¢{EmpName] = u[EmpName] ‘ave DEPT(t{Deptld] = (Deptld]))} | Databases | 597 Which of the above queries are safe? @Tand Ionly — ) Land Ill only (@ Wand HM only @ I, Mand IT [2017 (Set-1): 1 Mark] Consider a database that has the relation schema CR(StudentName, CourseName). An instance 431 Consider the relations r(A, B) and s(B, C), where s.Bis a primary key and r-B is a foreign key referencing s.B. Consider the query Q:1s (6p.5(9)) Let LOJ denote the natural left outer-join operation. Assume that rand s contain no null of the schema CR is as given below: values cR Which one of the following queries is NOT Student Name | Course Name equivalent to @? SA CA @ dges(r>d 8) b) Gy.4(7 LOI 8) SA cB © LOI C,.,(8) @ G,.,(7) LOI s SA co [2018:2 Marks] SB cB SB oC 482 Consider the following relations PQ, Y. 2), QU, sc CA Y, T) and R(Y, V). sc cB 80 co @ Rk] sD CA x) Y¥ [Zz x} YT YiV en} cB mi wfa|felwle2 |[wi[u SD ce xt | yt | 22 xt | Y2 0 aw 4 5 | [wl SE CD xlwlalilalule || wi. SE CA x2 | v4 | Z4 x3} Y3 | 1 y2 | v2 SE cB SF CA How many tuples will be returned by the following SF cB relational algebra query? ee ee TG pyenyonvev9 ® ¥ RB) ~MGqyeny.gr>s The following query is made on the database, Ty — ReourseName (studentName='sa\(CR)) 1, -CR*T, ‘The number of rows in 7, is [2017 (Set-1) :2 Marks] (QxR) [2019:2 Marks} 0 GATE Previous Years Solved Papers: EEEIZEM Relational modet: Relational algebra and Tuple Calculus 44 @ 45 () 46 © 47 © 48 © 49 (© 410 (b) 411 @) 412 (© 413 (b) 414 @) 415 (©) 4.16 @) 4.17 (b) 418 (b) 4.19 (©) 4.20 @) 421 (©) 422 (a) 4.23 (b) 424 (a) 4.25 (a) 4.26 (a) 4.27 @) 4.28 (c) 4.29 @) 431 © REISE *elational Model: Relational Algebra and Tuple Calculus a Giiso.. No For given instance “A” values unique doesn't mean candidate key. Because candidate key identification is based on constraints of the DB design and is not based on particular instance, Tass. RoS=R-R-S) so. (a) Determines titles of the books issued to user with user# 6 (b) determines name of authors of books that are issued to users who have home town ‘Delhi’ Tq, 6R)) 9 FR) Ifthe selection condition (c,) is on attribute over A, then we can not replace LHS expression by RHS expression. In RHS first projection is on {A then selection condition c, will fail because noA,. Ho 5 Whenever there is no foreign key constraint between two tables then the max. & min. no. of tuples in their join is mn and 0 respectively. me ‘The given tuple calculus expression give tuples where A = 10 & B= 20of relation r. ‘Therefore, relational algebra expression G49 2) 09g =29(0) is equivalent to given tuple caleulus expression. Gale ‘Aggregate operations like sum, average, count can't be expressed in terms of basi¢ relational algebra operations. Aggregate function requires extended relational algebra. (Min, Max can be expressed using basic RA operations) wo ‘The query {t| -(t R,)} is syntactically correct, However, it ask for all tuples t such that tis not ink, ‘That set of such t tuples is obviously infinite, in the context of such as the infinite domain set of all integers. Therefore, this is unsafe query. i Every query that can be expressed using a safe relational calculus query can also be expressed as relational algebra query. ‘Therefore, relational algebra has the same power as safe relational calculus. cb) RA,B,C) ROE) Cis the foreign key in R, and referring to primary key of R, Dis the primary key of R,. Inrelation R, column D values are superset or equal of R, column C, Because of integrity constraints. So m¢(R,)~my(R,) is empty. @ ‘The given query computes the names of girl students with more marks than all the boy students. we Given, R = (A, B, C, D) n=Macl) y=) sar tty On applying Natural Join all the tupples which are there already, willbe presentin S apart from thisis some tupples have duplicate values ofA’, then the resultant tupples will increases. Hence, rc s is the correct answer. ‘SQL query will return following tupples: ‘Number of tuples in relation r = 1000 Each value of A is appeared twice, because uniformly distributed in (0, 500] : ‘output eontain Sqciqq (t) returns 200 tuples. 6 duplicate since distinct hostel Sop = ie: a As b is very small compared to a and d which a 5 is also taken in account. 5 ; a ; Syciysrapar branch which already filter city as agra making it small, and before that Gao ‘in So number of tupples are 7. account P< depositor filter and give selected ‘tof Select operation in Relation algebra by default tables so >< between them will give same result return distinct attributes i.e. and better one. Tosa Bg tafe 7 Let the tables are like sed 6 Stud Info 5 Studld | Name | Sex wer ‘Sonumber of tupples are 3. 1 | Sita | F The difference between the number count ; x = Number of (SQL) - Numb 51-354 : lumber of (SQL) ~ Number (RA) + lseenl a ie 5 _|Radha| F Enroll Given three relational query languages have Sulit Coueld ary same expressive power. T x = 3 A He hs uy Enroll (Student, Course) paid (Student, amount) 2 B eu Assume that amounts 6000, 7000, 8000, 9000, a B 10000 were each paid by 20% ofthe students b {3 Plant: Rourge{ Enroll >< o(paid) a go sil snount>X 2] D boy 7 D Plan: Tore Ga rd vai} Now the query tata C.ex «emai (Stud Info)) results in IfX = 5000 Plan] Plan2 join cost equal because S{Stadia amounts of paid relation are greater than 5000. i between Plan required (amount > 5000) A comparisons only to paid relation and Plan2 5 requried (amount > 5000) comparisons to the a (Enroll) tich result of Enroll DIS. TL is not equivalent as it may also include Ps where Qs are not same in R and. le R(A,B,C)S(C) Ly g)—Rp_ gly g(R)*S— Ry Rg(B)— Mya (P) RS) —Ayo TL. ttle ene SG@Ve RU=V[S] at = VIR-8))} “ABY of R and for every “C” of S there must, be some C of R which equal to A, Band C. Which also equal to R/S. IIL. TRC query which equal to SIR. IV. SQL query equal toR Dd 8. Soquery [and ITare equal. ae Suppliers id) | Catalog (i pid | Pars id elo 5, sh | % red % SP] Py ed 8: S, P| Py bh 8, 5, P| Py dhe 8, P|, ereen 81 Ps sid’s supplied sids not in [epee norm Ih id's of parts whieh are not blue whose pid sr A or Py S| SFr Ps S| Srtr Sy Sy Py S| SP 4 L+—— sidts supplied some blue part ——>. Sy r [$+ oraytnpr 125 Suppliers (Sid, Sname, City, Street) 1, Each supplier and each street within a city hasa uniquename Sid Street City > Sname 2, (Sname, city) forms candidate key so that (Sname city) —>Sid Street 3. Sid primary key so that, Sid > Sname City Street Each FD of above satisfy BCNF. EASY | Databases | 601 BiB “EE “EE RCD) aft] [ale Bis a foreign key and referring to C and C is candidate key ReR PER, So, Ty(r,)—Metr,) n(faTeTe Eg, 1[s]7}+e = [oat ' R R [Nail 9 +e AIB CID R contains e, f, g but not a, b. iW 1/8 5/1 Ble 26 6/2 I. {t|3ue EMP(t{EmpName] = u[EmpName] 3/7 7/3 ave DEPT(t{Deptld] # v[Deptld] All ae \((Deptlad] + {Deptld))} results empname who does not belongs to 6,8} any departments (safe query). IL. {t|3u¢ EMP(t{EmpName] = u[EmpName] A ave DEPT(t{Deptld] + v[DeptId)))} results empname who does not belongs to O)Mgle,) Mele) =6 some departments (safe query). IIL {t|3u ¢ EMP(t{EmpName] = u[EmpName] a3ve DEPT(t{Deptld] = vfDeptld))} results empname who belongs to same Now, (B) Mo(t,)—My(r))= (ON glr) Mele.) {5,7} {5, 6, 7, 8} i SQL WUeFY | AN four queries i RAguery departments (safe query). " Correct for + All are safe queries. iii TRC query Given specification iv DRC query Eso. Ee Course Name 1 Join will have fewer number of disk block 1, result “ accesses if outer loop has smaller relation ce (rR). te 1, result : CR = T, = student name for which (@) ‘ every course name of CA, CB, CC is F gpMPLOVEE) — Ryo (@MPIOVEE Pea Sh dependent) emp dept) Ps y Ee 4 tuples in result Where, SD SF O Megypig (@mPlOYeE > eonpidneldplempAge< depAge) Et dependent) He Means y Allemployees whose ageis less than or equal to r[ayO] s[epe that ofall ofhis dependents. % [2 Ame G Rmpialemployee) ~ Rupig (employee [4 ole >< enpidadjenptge (65.5(8)) [AT BTO alle lala af 4 [a pTx yz] ay v xv Zt wow A:og.s(rbds) [A] BIC xo 2 ye ve fafa af 4a x WW ve a} 41a x2 Ya 24 TY2_ v2 B: 6,25 (r 4s) [A] BIC X ala fa Tp yenyanveva!® *B) = Py [ala os] 4 te ajx yY T R} Yo ov mou 2 woM Cir D4 ,<5() [AJB] © AE x Yoh ys v2 ests x 16 8 fo] | A x3 Y3 1 Y2 V2 ay 6 [Nall | 6 [Nall X TO qy-ny.ar>n(@* RB) = Pye D: 6p. (0) 24s [AT BIC | alefa nox eet alal TI fg] one record in result estate Option “c” query result not equal to given query. Transactions & Concurrency Control 5.1 For the schedule given below, which of the following is correct? 1 ReadA 2 ReadB 3 WriteA 4 Read A 5 Write A 6 Write B 7 ReadB 8 WriteB (@) This schedule is serializable and can occur in a scheme using 2PL protocol. (b) This schedule is serializable but cannot occur ina scheme using 2PL protocol. (©) This schedule is not serializable but can occur in a scheme using 2PL protocol. (@ This schedule is not serializable and cannot occur in a scheme using 2PL protocol. [1999: 2 Marks} 52 Which of the following scenarios may lead toan irrecoverable error in a database system? (@) A transaction writes a data item after itis read by an uncommitted transaction () A transaction reads a data item after it is read by an uncommitted transaction (@ A transaction reads a data item after it is written by a committed transaction (@ A transaction reads a data item after it is written by an uncommitted transaction [2003 : 1 Mark] 53 Consider three data items D1, D2, and D3, and the following execution schedule of transactions T1, T2 and 73. In the diagram, RD) and W(D) denote the actions reading and writing the data item D respectively. 7 n 7 IDs): ROD; we, . Re RDS) RD}; Wn; wo; Ws, ROY; Re; wn, won: BA BS 56 (@) The schedule is serializable as T2; 3; T1; (@) The schedule is serializable as T2; T1; T3; (©) The schedule is serializable as 3; T2; Tl; (@) The schedule is not serializable [2003 :2 Marks] Which level oflocking provides the highest degree of concurrency in a relational database? @) Page (b) Table (© Row (@ Page, table and row level locking allow the same degree of concurrency (2004 : 1 Mark] Consider the following schedule S of transactions TlandT2: 77 By Read) AzA10 Read) ‘Temp=02*A Write ReadlB) Write) Read) B=B+10 Write) B=B+ Temp Write Which of the following is TRUE about the schedule S? (@) S is serializable only as T1, T2 (0) Sis serializable only as T2, TL (©) Sis serializable both as 71, T2 and T2, TL (@ Sis not serializable either as Tl or as T2 [2004 : 2 Marks) Amongst the ACID properties ofa transaction, the ‘Durability’ property requires that the changes made to the database by a successful transaction persist (@) Except incase of an Operating System crash (b) Except in case of a Disk crash (Except in case of a power failure (@ Always, even if there isa failure of any kind [2005 : 1 Mark] 604 | GATE Previous Years Solved Papers: [J | MADE Easy 5:7 Consider the following log sequence of two @ Si: sa: transactions on a bank account, with initial lock S(A); lock SB); balance 12000, that transfer 2000 to a mortgage read (A); read (B); payment and, then apply a 5% interest. lock SB); lock S(A); 1. Tistart read (B); read (A); 2, T1:Bold=12000, new= 10000 ifA=0 ifBe0 3 n Bc SO er 20 then BE BH; then Ac Ax; 4, Tl:commit i te (B); ite (A); 6. T2:Bold= 10000, new = 10500 \ a unlock (A); unlock (BY; unlock (B); unlock (A); Suppose the database system crashed just before log record 7 is written, When the system is © Si: S2: restarted, which one statement is true of the lock X(A);, lock X(B); recovery procedure? read (A); read (B); (@) We must redo log record 6 to set B to 10500 lock X(B); Jock X(A); 0) Wemust undo log record 6 to set B to 10000 read (B); read (A); and then redo log records 2 and 3 ifA=0 ifBeo (© Weneed not redo log records 2 and 8 because then Be BH; — then AC AX; transaction TI has committed write (B); write (A); (@ We can apply redo and undo operations in unlock (A); unlock (A); arbitrary order because they are idempotent commit; commit; (2006: 1 Mark] unlock (B); unlock (A); 5.8 Consider the following schedules involving two @ Si: Si: transactions. Which one of the following Jock S(A); lock S(B);, statements is TRUE? read (A); read (B); 8): 1,00;1 (0); 2,080; r,(0); w_ 0) #00) lock X(B); lock X(A); Sy2 7%); 7,@; 1,0); We; 20; wy) read (B); read (A); (@) Both S, and §, are conflict serializable Ee SoD A) @ §, is conflict serializable and 8, is not conflict then Be Btl; then A A~ 15 serializable write (B); write (A); © S isnot conflict serializable and, isconflet unlock (A); unlock (A); serializable commit; commit; (@ Both S, and §, are not conflict serializable unlock (B); unlock (A); [2007:2 Marks] @ Si: s2: , . Tock S(A); lock S(B); 59 Comidertefiwing vo rans: and ra as lock XB); lock X(A); Te Te read (B); read (A); rread(A); read(B); ifA=0 ifB20 read: ready, then Be BH; — then Ae A-l; TA=0thenBeB+ 1; | HBe0then AC A-1; write B); write (A); — a unlock (A); unlock (A); ‘Which of the following schemes, using shared unlock (B); unlock (B); and exclusive locks, satisfy the requirements for commit; commit; strict two phase locking for the above transactions? [2007 : 2 Marks) EASY | Databases | 605 Consider the following three schedules of transactions TI, T2 and 73. [Notation: In the following NYO represents the action Y (R for read, W for write) performed by transaction N on object 0). Si: 2RA 2WA SRC 2WB 3WA 3WC IRA 1RB 1WA 1WB 82: SRC 2RA 2WA 2WB BWA IRA IRB 1WA 1WB 3WC $3: 2RA SRC 3WA 2WA 2WB 3WC TRA IRB 1WA 1WB Which of the following statements is TRUE? (@) $1, $2 and $3 are all conflict equivalent to each other () No two of $1, $2 and $3 are conflict equivalent to each other (©) S2isconflict equivalent to $3, but not to $1 (@ Slisconflict equivalent to $2, but not to $3 [2008 : 2 Marks} Consider two transactions T, and T,, and four schedules S,, 8,, 8,, 8, of 7, and T, as given below: T,:R,b] W, [x] Wily] ‘T, :Ryfx] Roly] W,[y] Sy: Ry Gx] Rylx] R,[y] W, fx] W, Ly] W, fy] 8, REx} Rol] Roly] W, lx) Waly] W, Ly] S,:R,Es] W, Lx] Ry{x] W, Ly] Ry fy] Waly] S,: Rolx] Roly] Ribs) WE) W,[y] WeL] Which of the above schedules are conflict- serializable? (@) S,andS, () 8,and8, © S,only @ S,only [2009 : 2 Marks] Which of the following concurrency control protocols ensure both conflict serializability and freedom from deadlock? 1. 2-phase locking IL Time-stamp ordering @) Tonly ©) Honly © Both Tand IT @ Neither Inor II ks} [2010:1 Mark} 5.13 Consider the following schedule for transactions ‘1, T2and T3: 11 T 73 Read 0) Read (Y) Read (Y) Write (y) Write &) Write (%) Read ®) Write &) ‘Which one of the schedules below is the correct serialization of the above? @ T1313 > T2 ) T25T1 > T3 @ R2BoT @ 9M 5T2 [2010: 2 Marks} 5.14 Consider the following transactions with data items P and Q initialized to zero: T,: read(P); read (Q); if P=0 then @:=Q+1; write (Q); T,: read); read (P); if Q=O then P:=P +1; write (P); Any non-serial interleaving of T, and, for concurrent execution leads to (@) aserializable schedule (©) aschedule that is not conflict serializable (©) aconflict serializable schedule (@ a schedule for which a precedence graph cannot be drawn [2012:2 Marks] 5.15 An indexis clustered, if @) itis ona set of fields that form a candidate key. () itisona set of fields that include the primary key. (©) the data record of the file are organized in the same order as the date entries ofthe index (@ the data records ofthe file are organized not in the same order as the data entries of the index. [2013 :1 Mark] 606 | 516 517 5.18 GATE Previous Years Solved Papers: Consider the following four schedules due to ‘three transactions (indicated by the subscript) ‘using read and write ona data item, denoted, by rx) and w(x) respectively. Which one of them is conflict serializable? G) rarer ws © rsAhsr yh ,o}s rw © reGIrLdsn Os weir @ res wir@ Owe {2014 (Set-1):2, Marks} Consider the following schedule Sof ‘transactions ‘71,72, T3 and TH: foe Reads() Writes) Commit Writes) Commit Writes(?) Reads(2) Commit Reads(X) Reads(V) Commit Which one of the following statements 1 CORRECT? @ ‘is onfict-serializable but not recoverable (b) Sisnot conflict serializable but istecoverable © $isboth conilict-serializable and recoverable (@ Sis neither conflct-serilizable nor 5 it recoverable [2014 (Set-2):2 Marks} Consider the transactions T1, 72, and 73 and the schedules $1 and S2 given below. Tier Kr Dwi Kiwi Tr r2 (N72 (Ds 02D ‘73:73 (W); 73 0X); w3 si: (a) 13 (Br (XY 72 Hs 72 (Zi WBN, w2 (2); (2); wi); 012) Sa: (a8 (89572 (Ms 73 Os PHD): PAZ 08 (¥); 11 (X); w2 (2) wi) Which oneof the following statements about the schedules is TRUE? {@) Only Slisconflict-serializable. o Only S2isconflictserializable. © Both $1 and $2 are conflict serializable. (@ Neither $1 nor $2 conflict-serializable [2014 (Set-3):2 Marks} 5.19 5.20 52 Consider the following transaction involving two bank accounts xand y. — 50; write (a); read (9); +50; write () ‘The constraint that the sum of the accounts x andy should remain constantis that of (@) Atomicity (b) Consistency (© Isolation @ Durability [2015 (Get-2):1 Mark] read (a) 53 zy Considera simple checkpointing protocol and the {ollowing set of operations in the log. (etart, TA) (write, TA, y, % 8): (tart, TDs (commit, T4); (write, TH, 2, 5, Ds (checkpoint); (etart, 12); (write, T2, x, 1, 9; (commit, T2), (start, T3); (write, T3, 2, 7,2 {fa 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 (@ Undo: T3,T1; Redo: 72 0) Undo: 3, T1; Redo: T2, M4 (0 Undor none; Redo: 12, T4, 73, TL (@ Undo: T3, T1, T4; Redo: T2 {2015 (Set-2) :1 Mark] Consider the following partial Schedule involving two transactions TL and T2. Only the read and the write operations have been shown. ‘The read operation on data item P is denoted by read(P) and the write operation on ata item Pis denoted by write(P). ‘Transactionid n R 1 readta) 2 write) 3 real) 4 writ) 5 read) 6 vwrite(B) 7 read(A) 8 commit 2 read) Suppose that the transaction TI fails immediately after time instance 9. Which one of the following statements is correct? 5m (@) 72 must be aborted and then both 71 and T2 must be restarted to ensure transaction atomicity (@) Schedule $ is nonrecoverable and cannot ensure transaction atomicity (© Only 72 must be aborted and then restarted. to ensure transaction atomicity @ Schedule $ is recoverable and can ensure atomicity and nothing else needs to be done [2015 (Set-3) :2 Marks] Consider the following directed graph: (8) —-©) @ D O—©) ‘The number of different topological ordering of the vertices of the graph is A [2016 (Set-1) :1 Mark] Which one of the following is NOT a part of the ACID properties of database transactions? @) Atomicity (6) Consistency (© Isolation (@) Deadlock-freedom [2016 (Set-1) :1 Mark] Consider the following two phase locking protocol. Suppose a transaction T accesses (for read or write operations), a certain set of objects {0,,..0,}. This is done in the following manner: Step 1. Tacquires exclusive locks to O,,..,0, in increasing order of their addresses, Step 2. The required operations are performed. Step 3. All locks are released, ‘This protocol will (@) guarantee serializability and deadlock- freedom ©) guarantee neither serializability nor deadlock-freedom (©) guarantee serializability but not deadlock- freedom @ guarantee deadlock-freedom but not serializability [2016 (Set-1) :2 Marks] | 607 5.25 Suppose a database schedule $ involves transactions 7,,.., 7,. Construct the precedence graph of $ with vertices representing the transactions and edges representing the conflicts. If $ is serializable, which one of the following orderings of the vertices of the precedence graph is guaranteed to yield a serial schedule? (@) Topological order (b) Depth-first order (© Breadth-first order (@) Ascending order of transaction indices [2016 (Set-2): 1 Mark] 5.26 Consider the following database schedule with ‘two transactions, 7, and $= rj 7; 740); 1,04; MMs wn (Ws a,;a, where r(Z) denotes a read operation by transaction 7; on a variable Z, w)(Z) denotes a write operation by 7, on a variable Z and a, denotes an abort by transation 7, ‘Which one of the following statements about the above schedule is TRUE? @) Sisnon-recoverable (b) Sisrecoverable, buthas a cascading abort (©) Sdoes not have a cascading abort @ Sis strict [2016 (Set-2): 2 Marks} 5.27 Ina database system, unique timestamps are assigned to each transaction using Lamport’s logical clock. Let TS(F,) and TS(7,) be the timestamps of transactions T, and 7, respectively. Besides, 7, holds a lock on the resource R and 7, has requested a conflicting Jock 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(Z,) < TS(T,) then T, is killed else 7, waits Assume any transaction that is not killed terminates eventually. Which of the followings, ‘TRUE about the database system that uses the above algorithm to prevent deadlocks? GATE Previous Years Solved Papers: [J | MADE! 608 | (@ The database system is both deadlock-free V. The total number of conflict serializable and starvation free. schedules that can be formed by T, and 7, ig (6) The database system is deadlock-free, but not starvation free. [2017 Get-2):2 Marks} © ae nl 5.29 Consider the following two statements about not deadlock | database transaction schedules: (@ ‘The database system is neither deadlock- Strict two-phase locking protocol generates freenor starvation free conflict serializable schedules that are also [2017 (Set-1):2 Marks} vecoverable 5.28 Two transactions 7, and T, are given as II. Timestamp-ordering concurrency control Tr n(X) w(X) r(¥) w,(Y) protocol with enemas Write Rule can generate view serializable schedules that are Tey re{¥) wy(1) r4Z) wylZ) not conflict serializable. where r(V) denotes a read operation by Which of the above statements is/are TRUE? transaction Tjona variable Vand w(V) denotes (@ NeitherInorII 6) Tonly 1 write operation by transaction Ton a variable © Monly (@ Both Tend Il 2019: 1 Mark] 5.30 Consider schedule of transactions 7, and T, T, [RA RC WD WD [ Commit | 7] _[RB[wB| [RD] [WC Commit Here, RX stands for“Read(X)’ and WX stands for"Write(Q)”, Which one ofthe fllowing schedules is confit equivalent to the above schedule? @ RA[ RC] WD | WB | Commit T, [RB | WB | RD | WC Commit of RARO[WD| WB] [Commit 7, [RB|WB| RD : we Commit , [IR [RC [wo J ws Commit oth RB | WB] RD [WC Commit o pa lRe[we WB| [Commit @ Tr RB|WB/RD| [Wo Commit (2020: 2 Marks} wers Transactions & Concurrency Control @ 52 @ 53 @ 54 © 55 @ 56 @) 57 (b) 58 © 59 @& 510 (c) 5.11 (b) 5.12 (b) 5.13 (a) 5.14 (b) 5.15 (c) 5.16 (a) 5.17 (0) 5.18 (a) 19 (b) 5.20 (a) 5.21 (b) 5.23 (@) 5.24 (a) 5.25 (a) 5.26 (c) 5.27 (a) 5.29 (@) 0 (b) ad Initial read of Ais done by'T, whereas final write of Bis also done by T,. Therefore W,(A), Ry(A) and W,(B), R,(B) are conflicting pairs. The schedule is neither T, > T, nor T, > T, serializable. Since schedule isnot serializable, it. can’t oecur in a scheme using 2PL protocol. TZ o | % RO) RX) woo RX) Not forms Not forms irrecoverable irrecoverable | % @ Ui Wa) wa) Count Re) RX) Count Committed read not forms irrecoverable _Dirty read may cause irrecoverable of 7, commit before CIR of 7, @ . ‘We have sequence W2(D2) + W1(D1). Which means T2 — TI whereas we also have W1(D1) > R2(D1) which means T1 > T2, Both are not possible. Therefore, schedule is not serializable, | When we move downmerd, conexsreny i inereaed So degree of concurrency is highest when lock is applied on rows, Transactions & Concurrency Control 4 He S is not serializable because T and T2 forms a cycle. mo “Durability” property requires that the changes made to the database by a successive transaction, persist always even in every kind of failure, Hao As per the recovery shcemes used, in database there is a need to undo all the write_item operations of the active transaction from the log and redo the write_item operations of the committed transactions from the log. Hence, we must undo log record 6 and redo log records 2 and 3. (C) Consider the table for transaction Ss, S, ns £05 ns 100); 1); (ys ml ys woh wy) 1); WO WiCX)5 ‘There is no serializable conflict in transaction 8, but for statement w, (x); there is a conflict in S, but itis also serializable He According to 2-phase locking protocol no Locking can be done after the first Unlock. According to Strict 2PL all exclusive locks should be released after the commit, In option (c) no exclusive lock release until commit operation. Hence a strict 2 PL property satisfied. GATE Previous Years Solved Papers : | MADE: 610 | 0 He @ Schedule SI: 2RA, 2WA, 3RC, 2WB, 3WA, Schedule $2 SW, 1RA, IRB, 1WA, 1WB. n|R RIX] nlm Ray RIX] way RLY) RO, wi} we) wy) way we) wo ES dependency graph eH ‘S2have no cycles. Schedule $3 $1 is conflict serializable. ae T2373 3TL RX a (i) Schedule $2: 3RC, 2RA, 2WA, 2WB, 3WA, oe 1RA, IRB, 1WA, 1WB, 3WC. RIX] n[ mf wiv) RO, RLY) Ra) wy) way a we dependency graph Ra $8 also have no cycles. na So $2 &S3 are conflict-serializable. we) wo Haw In 2-phase locking concurrency control protocol 82 is conflict serializable, it ensures the conflict serializable schedule but jaa it may not free from deadlock. Ex. $1 is conflict equivalent to $2. (ii) Schedule $3: 2RA, 3RC, 3WA, 2WA, 3WB, 3WC,IRA, IRB,IWA,1WB. WA) u[R[t . WO) peed BAY Dewy oa RO —. aay way T, inwaiting (py wa) way T, for unlock “me a Intime stamp ordering protocol it ensure conflict RA) © serializablity and free from dead lock. RB) Way (a) wi m By using the precedence graph we solve thus $3 is not conflict serializable, problem ‘Therefore S1 and $2 are conflict cycle equivalent schedules but $3 is not equivalent to $1 and $3. {EASY | Databases j len) 1, Read (x) nT, is followed by write (x) in T, 2, Read (x) in’T, is followed by write (x) in'T, 3, Read (y) in T, is followed by write (y) in 7, Soiit inclear from precedence graph. O-O-& rQ r,(P) Cycle present so not conflict serializable, Clustered index sort the data in the table based on their key values of the column on which clustered indexis created, So option (0) is correct. but 7 0) re) wy (8); 790; 90) e (? & ® Contains eyele; Not conflict serializable 10): (0); W400), 790)5 010) Contains cycle; Not conflict serializable rele) rls 70; wa) 2,00 ® Contains cycle; Not conflict serializable ra) wale; ra) 0 0) S @ @ Qa l) @ hus :) a ©: Not contains cycle; conflict serializable. Hae O—-@B—-O—-) Wo yee ++ Conflict serializable and itis also recoverable. He Si: r1(X); r3(¥); r3(X); r2(¥); r2(Z); w3(¥); w2(Z);ri(Z); w1(X); wi (Z) ® ® © Nocycle = S1is conflict serializable. S2: r1(X); r3(¥); r2(¥); rB(X); r1(Z); r2(Z); w3(Y); w1(X); w2(Z); wl(Z) oO 2 jo SW Cycle > S2isnot conflict serializable. He Consistency ensures the given constraint. le The transactions that committed before checkpoint can be ignored as their updations are retained in data base, ‘Those transactions that are committed after checkpoint can be repeated (REDO). The transactions that are not committed after checkpoint have to be UNDONE UNDO : 73, TIM T1 and T3 are not committed after checkpoint REDO : T2 /! T2 committed after checkpoint |) T, writes on A. T, is performing read operation on A, and 7, commits before 7, Hence it’s DIRTY Read or Uncommitted Read. Hence it's non-recoverable as 7, is committed before 77, commit. It can not ensure transaction atomicity, ‘Number of topological orders: 6 abedef abdecf adbecef adbeef adebef adbecf Ele ACID stands for A: Atomicity C: Consistency T:Isolation D: Durability So, deadlock-freedom is not the ACID property. (a) 2PL over objects O, .. O, Step-1: T acquires exclusive lock to O, . O in increasing order of their address. ‘Step-2: The required operations are performed. Step-3: All locks are released. Because of 2PL it guarantee serializability and objects locks in increasing order of address and all objects locks before read/write which avoids deadlock. ae For acyclic precedence graph of conflict serializable schedule equal serial schedule is topological order of acyclic precedence graph. He ‘No uncommitted reads so that its casecadeless rollback recoverable because Tw,(x) before T, commit / Rollback T,w,(x)- So not strict recoverable. 7 Lh oo} 1) 1) 0) 10) 2) GATE Previous Years Solved Papers: [J | MADEEASy le 77, holds lock on resource R, 1, requires conflict lock on same resource R Wait for graph if TS(T,) < TS(T,) ‘Then T, killed [restart with same TS value] else 7, waits. Avoids both deadlock and starvation, Sol. T, : 7X) wX) AV) WY) 1, r4(¥) AY) 12) WZ) ( Number of conflict serializable on T, >T,:1._ CX) w,(X) 1(Y) w, CY) ry(V)wy8) 2,2) Ww) (i Number of conflict serializable on T, >, 53 $= n,(¥) we(¥) 1,() wyC¥) (8) w (X) must be before r,(¥) So that (¢,(¥) w(¥)) (8) w,(20) ean place. 40, = 6 ways. 1. ng(¥) w4¥) 2,09) w,00) 4) w,(Y) 1,(Z) w,(Z) ean place in ®C, = 15 ways. 2, ng(¥) 1408) Wy(8) w(¥) ¥,(¥) WC) 1,(Z) w,(2) can place in *C, = 6 ways. 3. n4(¥) 708) wy CH) (8) 1(¥) CY) 1,(2) w,(2) can place in °C, = 10 ways. 4,0) w,09 1,(¥) (1) 11(Y) #0) 1(Z) w,(Z) can place in ‘C, = 6 ways. 5, 108) 1,(¥) wAC¥) w,00 2,(¥) 9 (Y) 1,2) w,(Z) can place in °C, = 10 ways 6. 7 (8) 1,(¥) w,00 wg) 1,0) w,(Y) 1,(2) w,(Z) can place in *C, = 6 ways. ‘Total conflict serializable of T, and T, = 53+1 54 ways, I. Strict 2PL guaranteed conflict serializable because of 2PL condition and also strict recoverable. TI. Thomas Write time stamp ordering ensures serializable. Thomas write rule time stamp ordering allowed to execute schedule which is view equal serial schedule based on time stamp ordering, Tae nt nia) oo 18) w{B) (B) wo | . 40) no 0) Conf uO) wfc) | >? Confit equal w(0) 0) “0 ‘Commit "o Commit Commit Commit Conflict equal [613 File Structures — 61 62 63 64 65 Which of the following is correct? (a) B-trees are for storing data on disk and B* trees are for main memory. (b) Range queries are faster on B* trees. (©) B-trees are for primary indexes and B* trees are for secondary indexes. (@ The height of a B* tree is independent of the number of records. [19991 Mark] ‘Br-trees are preferred to binary trees in databases because @) Disk capacities are greater than memory capacities (0) Disk access is much slower than memory access (© Disk data transfer rates are much less than ‘memory data transfer rates (@ Disks are more reliable than memory [2000: 1 Mark] AB‘ treeindexis tobe built on the Name atribute of the relation STUDENT. Assume that all student names are of length 8bytes, disk blocks are of size 512 bytes, and index pointers are of size 4 bytes. Given this scenario, what would be the best choice of the degree (ie, the number of pointers per node) ofthe BY-tree? + @ 16 w 2 O48 @u [20022 Marks) ‘The order ofan internal node in a B* tree index {s the maximum number of children it can have, Suppose that a child pointer takes 6 bytes, the search field value takes 14 bytes, and the block size is 512 bytes. Whatis the order of the internal node? @ a © 26 ) 25 @x [2004:2Marks} Consider a table Tin a relational database with a key field K. A B-tree of order p is used as an ‘access structure on K, where p denotes the max imum number of tree pointers in a Betree index node. Assume that K is 10 bytes long; disk block size is 512 bytes; each data pointer P, is 8bytes long and each block pointer P, is S bytes long, In order for each B-tree node to fit in a single disk block, the maximum value of pis. @ 0 (b) 22 © B @ 3 [2004 : 2 Marks) 66 Which one of the following is a key factor for preferring B*-trees to binary search trees for indexing database relations? (@) Database relations have a large number of record (b) Database relations are sorted on the primary key (© BY-trees require less memory than binary search trees (@ Data transfer from disks isin blocks [2005 :1 Mark} 6.7 AB-Tree used as an index for a large database table has four levels including the root node. Ifa new key is inserted in this index, then the maximum number of nodes that could be newly created in the process are @5 (b) 4 O38 @2 [2005 : 1 Mark] Linked Answer Questions 6.8 and 6.9: A database table T1 has 2000 records and occupies 80 disk blocks. Another table T2 has 400 records and occupies 20 disk blocks. These two tables have to be joined as per a specified join condition that needs to be ‘evaluated for every pair of records from these two tables. ‘The memory buffer space available can hold exactly one block of records for T1 and one block of records for T2 simultaneously at any point in time. No index is available on either table. 68. If Nested-loop join algorithm is employed to perform the join, with the most appropriate (a) 800000 (© 32020 (b) 40080 @ 100 [2005 : 2 Marks} If, instead of Nested-loop join, Block nested-loop join is used, again with the most appropriate choice of table in the outer loop, the reduction in number of block accesses required for reading the data will be @o (b) 30400 (©) 38400 (@ 798400 [2005 : 2 Marks} Ina database file structure, the search key field is Qbyteslong, the block size is 512 bytes, a record pointer is 7 bytes and a block pointer is 6 bytes. ‘The largest possible order of a non-leaf node in a B+ tree implementing this file structure is @ 3 4 © m4 @ 44 [2006 : 2 Marks} ‘The order of a leaf node in a B*-tree is the ‘maximum number of (value, data record pointer) pairs it can hold. Given that the block size is 1K bytes, data record pointer is 7 bytes long, the value field is 9 bytes long and a block pointer is, Gbytes long, what is the order of the leaf node? @ 63 Oe © 67 @ 68 [2007: 2 Marks} Directions for question 6.12 to 6.13: Consider the B* tree in the adjoining figure, where each node has at most two keys and three links ka 6.13 614 6.15 6.16 EASY | Databases jes choice of table to be used in outer loop, the number @1 (b) 2 of block accesses required for reading the data @3 @4 are [2007 : 2 Marks} ‘Now the key K50 is deleted from the B* tree resulting after the two insertions made earlier. Consider the following statements about the B* tree resulting after this deletion. () The height of the tree remains the same. i) The node[ K20]] (disregarding the links) is present in the tree, GiThe root node remains unchanged (disregarding the links) Which one of the following options is true? (@) Statements (i) and (i) are true (b) Statements (i) and (ii) are true (© Statements (i) and (i) are true (@ All the statements are false {2007 : 2 Marks] Aclustering index is defined on the fields which are oftype (@) Non-key and ordering (b) Non-key and non-ordering (© Key and ordering @ Key and non-ordering [2008 :1 Mark] Consider a file of 16384 records. Each record is 32 bytes long and its key field is of size 6 bytes. ‘The file is ordered on a non-key field, and the file organization is unspanned. The fileis stored in a file system with block size 1024 bytes, and the size ofa block pointer is 10 bytes. Ifthe secondary index is built on the key field of the file, and a multilevel index scheme is used to store the secondary index, the number of first-level and second-level blocks in the multilevel index are respectively (@) 8and0 () 128and6 (© 256and4 (@ 512and5 [2008: 2 Marks} ‘The following key values are inserted into a B* tree in which order of the internal nodes is 3, and that of the leaf nodes is 2, in the sequence given below. The order of internal nodes is the maximum number of tree pointers in each node, and the order of leaf nodes is the maximum number of data items that can be stored in it. ‘The B*- tree is initially empty.

You might also like