Database Management Systems Paper Solution

Similar documents
Techno India Batanagar Computer Science and Engineering. Model Questions. Subject Name: Database Management System Subject Code: CS 601

Delhi Noida Bhopal Hyderabad Jaipur Lucknow Indore Pune Bhubaneswar Kolkata Patna Web: Ph:

DATABASE MANAGEMENT SYSTEMS

CMSC 461 Final Exam Study Guide


Functional Dependencies CS 1270

Data about data is database Select correct option: True False Partially True None of the Above

A7-R3: INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS

SQL Interview Questions


Database Management

SYED AMMAL ENGINEERING COLLEGE

In This Lecture. Transactions and Recovery. Transactions. Transactions. Isolation and Durability. Atomicity and Consistency. Transactions Recovery

Fundamentals of Database Systems

CS/B.Tech/CSE/New/SEM-6/CS-601/2013 DATABASE MANAGEMENENT SYSTEM. Time Allotted : 3 Hours Full Marks : 70

CSE 544 Principles of Database Management Systems. Magdalena Balazinska Winter 2009 Lecture 4 - Schema Normalization

Relational Databases

CS403- Database Management Systems Solved Objective Midterm Papers For Preparation of Midterm Exam

Babu Banarasi Das National Institute of Technology and Management

QUIZ 1 REVIEW SESSION DATABASE MANAGEMENT SYSTEMS

E-R diagrams and database schemas. Functional dependencies. Definition (tuple, attribute, value). A tuple has the form

Relational Model and Relational Algebra A Short Review Class Notes - CS582-01

CS2255 DATABASE MANAGEMENT SYSTEMS QUESTION BANK UNIT I

Normalization. Murali Mani. What and Why Normalization? To remove potential redundancy in design

Relational Design: Characteristics of Well-designed DB

Sankalchand Patel College of Engineering, Visnagar B.E. Semester III (CE/IT) Database Management System Question Bank / Assignment

UNIT 3 DATABASE DESIGN

Rajiv GandhiCollegeof Engineering& Technology, Kirumampakkam.Page 1 of 10

INSTITUTO SUPERIOR TÉCNICO Administração e optimização de Bases de Dados

CS403- Database Management Systems Solved MCQS From Midterm Papers. CS403- Database Management Systems MIDTERM EXAMINATION - Spring 2010

II B.Sc(IT) [ BATCH] IV SEMESTER CORE: RELATIONAL DATABASE MANAGEMENT SYSTEM - 412A Multiple Choice Questions.

Name Class Account UNIVERISTY OF CALIFORNIA, BERKELEY College of Engineering Department of EECS, Computer Science Division J.

CSE 444, Winter 2011, Midterm Examination 9 February 2011

Name :. Roll No. :... Invigilator s Signature : DATABASE MANAGEMENT SYSTEM

Relational Model, Relational Algebra, and SQL

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition Chapter 10-2

Database Management System

DATABASE MANAGEMENT SYSTEM

Chapter 10. Normalization. Chapter Outline. Chapter Outline(contd.)

MIDTERM EXAMINATION Spring 2010 CS403- Database Management Systems (Session - 4) Ref No: Time: 60 min Marks: 38

CSCE 4523 Introduction to Database Management Systems Final Exam Fall I have neither given, nor received,unauthorized assistance on this exam.

ROEVER ENGINEERING COLLEGE

Functional Dependencies and Finding a Minimal Cover

Final Review. May 9, 2017

Final Review. May 9, 2018 May 11, 2018

CSE 444 Midterm Exam

Solutions to Final Examination

Unit 3 : Relational Database Design

Q.1 Short Questions Marks 1. New fields can be added to the created table by using command. a) ALTER b) SELECT c) CREATE. D. UPDATE.

MTA Database Administrator Fundamentals Course

8) A top-to-bottom relationship among the items in a database is established by a

NJIT Department of Computer Science PhD Qualifying Exam on CS 631: DATA MANAGEMENT SYSTEMS DESIGN. Summer 2012

Relational Database: The Relational Data Model; Operations on Database Relations

Chapter 10. Chapter Outline. Chapter Outline. Functional Dependencies and Normalization for Relational Databases

CSE 544 Principles of Database Management Systems. Magdalena Balazinska Fall 2009 Lecture 3 - Schema Normalization

Fundamentals of Database Systems

Unit- III (Functional dependencies and Normalization, Relational Data Model and Relational Algebra)

Relational Database design. Slides By: Shree Jaswal

Introduction to Transaction Processing Concepts and Theory

CS 245 Midterm Exam Winter 2014

Functional Dependencies & Normalization for Relational DBs. Truong Tuan Anh CSE-HCMUT

Final Review. Zaki Malik November 20, 2008

CPSC 421 Database Management Systems. Lecture 19: Physical Database Design Concurrency Control and Recovery

Final Review. CS 377: Database Systems

This lecture. Databases -Normalization I. Repeating Data. Redundancy. This lecture introduces normal forms, decomposition and normalization.

Introduction to Database Systems. Announcements CSE 444. Review: Closure, Key, Superkey. Decomposition: Schema Design using FD

Chapter 8: Relational Database Design

Conceptual (high-level, semantic)/ Physical (low-level, internal)/ Implementation (representational)

Databases -Normalization I. (GF Royle, N Spadaccini ) Databases - Normalization I 1 / 24

Midterm Review. Winter Lecture 13

ARTICLE RELATIONAL ALGEBRA

RELATIONAL ALGEBRA II. CS121: Relational Databases Fall 2017 Lecture 3

E.G.S. PILLAY ENGINEERING COLLEGE (An Autonomous Institution, Affiliated to Anna University, Chennai) Nagore Post, Nagapattinam , Tamilnadu.

CSE 562 Database Systems

Database Management

CS6302- DATABASE MANAGEMENT SYSTEMS- QUESTION BANK- II YEAR CSE- III SEM UNIT I

Transaction Processing Concepts and Theory. Truong Tuan Anh CSE-HCMUT

ADVANCED DATABASES ; Spring 2015 Prof. Sang-goo Lee (11:00pm: Mon & Wed: Room ) Advanced DB Copyright by S.-g.

Functional Dependencies and Normalization

Database Systems. Basics of the Relational Data Model

CS 564 Final Exam Fall 2015 Answers

Functional Dependencies and. Databases. 1 Informal Design Guidelines for Relational Databases. 4 General Normal Form Definitions (For Multiple Keys)

Administration Naive DBMS CMPT 454 Topics. John Edgar 2

In This Lecture. Exam revision. Main topics. Exam format. Particular topics. How to revise. Exam format Main topics How to revise

SYED AMMAL ENGINEERING COLLEGE

Relational Algebra. Procedural language Six basic operators

Chapter 14. Database Design Theory: Introduction to Normalization Using Functional and Multivalued Dependencies

CS411 Database Systems. 05: Relational Schema Design Ch , except and

Introduction to Query Processing and Query Optimization Techniques. Copyright 2011 Ramez Elmasri and Shamkant Navathe

TRANSACTION PROPERTIES

Information Management (IM)

More Normalization Algorithms. CS157A Chris Pollett Nov. 28, 2005.

Relational Algebra and SQL

VIEW OTHER QUESTION PAPERS

CSE 414 Final Examination. Name: Solution

INSTITUTE OF AERONAUTICAL ENGINEERING (Autonomous) Dundigal, Hyderabad

Chapter 20 Introduction to Transaction Processing Concepts and Theory

DATABASE MANAGEMENT SYSTEM SHORT QUESTIONS. QUESTION 1: What is database?

INSTITUTO SUPERIOR TÉCNICO Administração e optimização de Bases de Dados

CSE 344 Final Review. August 16 th

Transcription:

Database Management Systems Paper Solution Following questions have been asked in GATE CS exam. 1. Given the relations employee (name, salary, deptno) and department (deptno, deptname, address) Which of the following queries cannot be expressed using the basic relational algebra operations (U, -, x, π, σ, p)? (GATE CS 2000) (a) Department address of every employee (b) Employees whose name is the same as their department name (c) The sum of all employees salaries (d) All employees of a given department Answer: (c) The six basic operators of relational algebra are the selection(σ ), the projection(π), the Cartesian product (x) (also called the cross product or cross join), the set union (U), the set difference (-), and the rename (p). These six operators are fundamental in the sense that none of them can be omitted without losing expressive power. Many other operators have been defined in terms of these six. Among the most important are set intersection, division, and the natural join, but aggregation is not possible with these basic relational algebra operations. So, we cannot run sum of all employees salaries with the six operations. 2. Given the following relation instance. x y z 1 4 2 1 5 3 1 6 3 3 2 2 Which of the following functional dependencies are satisfied by the instance? (GATE CS 2000) (a) XY -> Z and Z -> Y (b) YZ -> X and Y -> Z (c) YZ -> X and X -> Z (d) XZ -> Y and Y -> X Answer: (b) A functional dependency (FD) is a constraint between two sets of attributes in a relation from a database. A FD X- >Y require that the value of X uniquely determines the value of Y where X and Y are set of attributes. FD is a generalization of the notion of a key.

Given that X, Y, and Z are sets of attributes in a relation R, one can derive several properties of functional dependencies. Among the most important are Armstrong s axioms, which are used in database normalization: * Subset Property (Axiom of Reflexivity): If Y is a subset of X, then X? Y * Augmentation (Axiom of Augmentation): If X -> Y, then XZ -> YZ * Transitivity (Axiom of Transitivity): If X -> Y and Y -> Z, then X -> Z From these rules, we can derive these secondary rules: * Union: If X -> Y and X -> Z, then X -> YZ * Decomposition: If X -> YZ, then X -> Y and X -> Z * Pseudotransitivity: If X -> Y and YZ -> W, then XZ -> W In the above question, Y uniquely determines X and Z, for a given value of Y you can easily find out values of X and Z. So, Y -> X and Y -> Z hold for above schema. From rule of augmentation we can say YZ->X. If we understand the notion of FD, we don t need to apply axioms to find out which option is true, just by looking at the schema and options we can say that (b) is true. 3. Given relations r(w, x) and s(y, z), the result of select distinct w, x from r, s is guaranteed to be same as r, provided (GATE CS 2000) (a) r has no duplicates and s is non-empty (b) r and s have no duplicates (c) s has no duplicates and r is non-empty (d) r and s have the same number of tuples Answer: (a) The query selects all attributes of r. Since we have distinct in query, result can be equal to r only if r doesn t have duplicates. If we do not give any attribute on which we want to join two tables, then the queries like above become equivalent to Cartesian product. Cartisian product of two sets will be empty if any of the two sets is empty. So, s should have atleast one record to get all rows of r. 4. 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 of the following pairs is not equivalent? (GATE CS 2000) (a) x = 5, not (not (x = 5) (b) x = 5, x > 4 and x < 6, where x is an integer (c) x < 5, not(x = 5) (d) None of the above Answer (c)

It doesn t need much explanation. For all values smaller than 5, x < 5 will always be true but x = 5 will be false. 5. Consider a schema R(A, B, C, D) and functional dependencies A -> B and C -> D. Then the decomposition of R into R1 (A, B) and R2(C, D) is (GATE CS 2001) a) dependency preserving and loss less join b) loss less join but not dependency preserving c) dependency preserving but not loss less join d) not dependency preserving and not loss less join Answer: (c) Dependency Preserving Decomposition: Decomposition of R into R1 and R2 is a dependency preserving decomposition if closure of functional dependencies after decomposition is same as closure of of FDs before decomposition. A simple way is to just check whether we can derive all the original FDs from the FDs present after decomposition. In the above question R(A, B, C, D) is decomposed into R1 (A, B) and R2(C, D) and there are only two FDs A -> B and C -> D. So, the decomposition is dependency preserving Lossless-Join Decomposition: Decomposition of R into R1 and R2 is a lossless-join decomposition if at least one of the following functional dependencies are in F+ (Closure of functional dependencies) R1 R2 R1 OR R1 R2 R2 In the above question R(A, B, C, D) is decomposed into R1 (A, B) and R2(C, D), and R1 R2 is empty. So, the decomposition is not lossless. Following Questions have been asked in GATE 2012 exam. 1) Which of the following statements are TRUE about an SQL query? P: An SQL query can contain a HAVING clause even if it does not a GROUP BY clause Q: An SQL query can contain a HAVING clause only if it has a GROUP BY clause R: All attributes used in the GROUP BY clause must appear in the SELECT clause S: Not all attributes used in the GROUP BY clause need to apper in the SELECT clause (A) P and R (B) P and S (C) Q and R (D) Q and S Answer (B) P is correct. HAVING clause can also be used with aggregate function. If we use a HAVING clause without a GROUP BY clause, the HAVING condition applies to all rows that satisfy the search condition. In other words, all rows that satisfy the search condition make up a single group. See this for more details.

S is correct. To verify S, try following queries in SQL. CREATE TABLE temp ( id INT, name VARCHAR(100) ); INSERT INTO temp VALUES (1, "abc"); INSERT INTO temp VALUES (2, "abc"); INSERT INTO temp VALUES (3, "bcd"); INSERT INTO temp VALUES (4, "cde"); SELECT Count(*) FROM temp GROUP BY name; Output: count(*) -------- 2 1 1 2) Given the basic ER and relational models, which of the following is INCORRECT? (A) An attributes of an entity can have more that one value (B) An attribute of an entity can be composite (C) In a row of a relational table, an attribute can have more than one value (D) In a row of a relational table, an attribute can have exactly one value or a NULL value Answer (C) The term entity belongs to ER model and the term relational table belongs to relational model. A and B both are true. ER model supports both multivalued and composite attributes See this for more details. (C) is false and (D) is true. In Relation model, an entry in relational table can can have exactly one value or a NULL.

3) Suppose (A, B) and (C,D) are two relation schemas. Let r1 and r2 be the corresponding relation instances. B is a foreign key that refers to C in r2. If data in r1 and r2 satisfy referential integrity constraints, which of the following is ALWAYS TRUE? Answer (A) B is a foreign key in r1 that refers to C in r2. r1 and r2 satisfy referential integrity constraints. So every value that exists in column B of r1 must also exist in column C of r2. 4) Which of the following is TRUE? (A) Every relation in 2NF is also in BCNF (B) A relation R is in 3NF if every non-prime attribute of R is fully functionally dependent on every key of R (C) Every relation in BCNF is also in 3NF (D) No relation can be in both BCNF and 3NF Answer (C) BCNF is a stronger version 3NF. So every relation in BCNF will also be in 3NF. Please see GATE Corner for all previous year paper/solutions/explanations, syllabus, important dates, notes, etc. Please write comments if you find any of the answers/explanations incorrect, or you want to share more information about the topics discussed above 1) Consider the following transactions with data items P and Q initialized to zero: T1: read (P) ; read (Q) ; if P = 0 then Q : = Q + 1 ; write (Q) ; T2: read (Q) ; read (P) ; if Q = 0 then P : = P + 1 ; write (P) ; Any non-serial interleaving of T1 and T2 for concurrent execution leads to (A) A serializable schedule (B) A schedule that is not conflict serializable (C) A conflict serializable schedule (D) A schedule for which a precedence graph cannot be drawn Answer (B) Two or more actions are said to be in conflict if:

1) The actions belong to different transactions. 2) At least one of the actions is a write operation. 3) The actions access the same object (read or write). The schedules S1 and S2 are said to be conflict-equivalent if the following conditions are satisfied: 1) Both schedules S1 and S2 involve the same set of transactions (including ordering of actions within each transaction). 2) The order of each pair of conflicting actions in S1 and S2 are the same. A schedule is said to be conflict-serializable when the schedule is conflict-equivalent to one or more serial schedules. Source: Wiki Page for Schedule In the given scenario, there are two possible serial schedules: 1) T1 followed by T2 2) T2 followed by T1. In both of the serial schedules, one of the transactions reads the value written by other transaction as a first step. Therefore, any non-serial interleaving of T1 and T2 will not be conflict serializable. 2) Consider the following relations A, B, C. How many tuples does the result of the following relational algebra expression contain? Assume that the schema of A U B is the same as that of A. Table A Id Name Age ---------------- 12 Arun 60 15 Shreya 24 99 Rohit 11 Table B Id Name Age ---------------- 15 Shreya 24 25 Hari 40 98 Rohit 20 99 Rohit 11 Table C Id Phone Area

----------------- 10 2200 02 99 2100 01 (A) 7 (B) 4 (C) 5 (D) 9 Answer (A) Result of AUB will be following table Id Name Age ---------------- 12 Arun 60 15 Shreya 24 99 Rohit 11 25 Hari 40 98 Rohit 20 The result of given relational algebra expression will be Id Name Age Id Phone Area --------------------------------- 12 Arun 60 10 2200 02 15 Shreya 24 10 2200 02 99 Rohit 11 10 2200 02 25 Hari 40 10 2200 02 98 Rohit 20 10 2200 02 99 Rohit 11 99 2100 01 98 Rohit 20 99 2100 01 3) Consider the above tables A, B and C. How many tuples does the result of the following SQL query contains? SELECT A.id FROM A WHERE A.age > ALL (SELECT B.age

FROM B WHERE B. name = "arun") (A) 4 (B) 3 (C) 0 (D) 1 Answer (B) The meaning of ALL is the A.Age should be greater than all the values returned by the subquery. There is no entry with name arun in table B. So the subquery will return NULL. If a subquery returns NULL, then the condition becomes true for all rows of A (See this for details). So all rows of table A are selected. GATE-2015 1. Consider the following transaction involving two bank accounts x and y. read (x) ; x := x 50; write (x); read (y); y := y + 50; write (y) The constraint that the sum of the accounts x and y should remain constant isthat of (a) Atomicity (b) Consistency (c) Isolation (d) Durability Answer: option (b) Consistency assures that after any transaction, the state of the database will remain valid. Database state refers to all stored values within the database at a given instance. A valid database must satisfy all constraints specified in the schema and over the database. In the above transaction, 50 has been deducted from x, and y has been incremented by 50. For the database to be valid after transaction, net amount x+y should remain constant before and after the transaction.this is ensured by property consistency. GATE - 2015 2. With reference to the B+ tree index of order 1 shown below, the minimum number of nodes (including the root node) that must be fetched in order to satisfy the following query: Get all records with a search key greater than or equal to 7 and less than 15 is.

Ans: 5 In a B+ tree, data pointers are stored only at the leaf nodes. The leaf nodes contain the value of the search field as well as a pointer to the record/block that contains the record.in order to provide ordered access, the leaf nodes have been linked. In the above question, in order to fetch all records with key values greater than or equal to 7 and less than 15, we first need to locate the leaf node that stores 7.To reach the node with key 7,we start from root with key value 9,follow left pointer to arrive at a node with key 5 (since search key 7 is less than 9). From node with key 5, we follow the right pointer to reach the leaf node with key value 7. Now we move from 7 till 15 sequentially towards right, thus traversing another 2 nodes. Thus total number of nodes fetched in order to satisfy the query is 5. GATE-2015 3. Consider two relations R1 (A, B) with the tuples (1, 5) (3,7)and R2(A, C) = (1, 7), (4, 9). Assume that R(A,B,C) is the full natural outer join of R1 and R2. Consider the following tuples of the form (A,B,C) a = (1, 5, null), b = (1, null, 7), c = (3, null, 9), d = (4, 7, null), e = (1, 5, 7), f = (3, 7, null), g = (4, null, 9). Which one of the following statements is correct? (a) R contains a, b, e, f, g but not c, d (b) R contains a, b, c, d, e, f, g (c) R contains e, f, g but not a, b (d) R contains e but not f, g Ans: option (c) R 1 : A B 1 5

3 7 R 2: A C 1 7 4 9 A full outer join of R1and R2 returns all rows of R1 and R2. Thus resulting relation R(A,B,C) is as shown below : A B C 1 5 7 3 7 null 4 null 9 Hence in the tuples correspond to e, f and g in the question. GATE-2015 4. Consider a simple checkpointing protocol and the following set of operations in the log. (start, T4); (write, T4, y, 2, 3); (start, T1); (commit, T4); (write, T1, z, 5, 7); (checkpoint); (start, T2); (write, T2, x, 1, 9); (commit, T2); (start, T3); (write, T3, z, 7, 2);

If a crash happens now and the system tries to recover using both undo and redo operations, what are the contents of the undo list and the redo list (a) Undo: T3, T1; Redo: T2 (b) Undo: T3, T1; Redo: T2, T4 (c) Undo: none; Redo: T2, T4, T3; T1 (d) Undo: T3, T1, T4; Redo: T2 Answer: option (a) The given set of operations can be rewritten as : T1 T2 T3 T4 start write(z, 5, 7) start Write(y, 2, 3) commit checkpoint checkpoint checkpoint checkpoint start write( x, 1, 9) commit start write( z, 7, 2) crash crash crash crash Checkpoint is a mechanism where all the previous logs are removed from the system and stored permanently in a storage disk. Checkpoint declares a point before which the DBMS was in consistent state, and all the transactions were committed. During recovery the system reads the logs backwards from the end to the last checkpoint. (Reference :http://www.tutorialspoint.com/dbms/dbms_data_recovery.htm ). In the question, transactions T1 and T3 are uncommitted hence these transactions are undone during recovery. T4 is committed before check pointing. Since T2 is committed after the checkpoint, it has to be redone. 5. A file is organized so that the ordering of data records is the same as or close to the ordering of data entries in some index. Then that index is called

(a) Dense (b) Sparse (c) Clustered (d) Unclustered Ans: option (c) With a clustered index the physical records (rows) are stored on the disk in the same order as that of index. Hence every table can have exactly one clustered index. All Other Gate Question Paper Year Wise with Answer Available in Soft Copy Format.