<<

DATABASE MANAGEMENT SYSTEM

For

DATABASE MANAGEMENT . SYSTEM SYLLABUS ER model. : , calculus, SQL. Integrity constraints, normal forms. File organization, indexing (e.g., B and B+ trees). Transactions and . ANALYSIS OF GATE PAPERS

Exam Year 1 Mark Ques. 2 Mark Ques. Total 2003 2 3 8 2004 2 5 12 2005 3 4 11 2006 1 4 9 2007 - 6 12 2008 1 5 11 2009 - 5 10 2010 2 2 6 2011 - 2 4 2012 2 5 12 2013 - 3 6 2014 Set-1 2 3 8 2014 Set-2 2 3 8 2014 Set-3 2 3 8 2015 Set-1 2 2 6 2015 Set-2 2 2 6 2015 Set-3 2 2 6 2016 Set-1 4 1 6 2016 Set-2 2 2 6 2017 Set-1 2 3 8 2017 Set-2 2 4 10 201

8 3 2 7

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission CONTENTS Topics Page No

1. THE ENTITY – RELATIONSHIP MODEL

1.1 Introduction 1.2 The E – R Model 1.3 (DBA) 01 1.4 The Entity Relationship Diagram 01 01 2. RELATIONAL MODEL 01

2.1 Levels of a Database System 2.2 The Attributes and of a Student 2.3 Keys 04 2.4 Relational 05 2.5 Network Data Modelling Concepts 06 06 3. TRANSACTIONS 08

3.1 Transactions 3.2 Serializable Schedule 3.3 Recoverability 11 3.4 Recoverable Schedules 12 3.5 Cascade less Schedules 13 3.6 Implementation of Isolation 13 3.7 Transaction Definition in SQL 13 3.8 Testing for Serializability 14 3.9 Tests for View Serializability 14 14 4. QUEL 14

4.1 Quel 4.2 Sequel 4.3 Assign to 15 4.4 SQL 15 4.5 Select Statement 15 4.6 Defining a Value 15 4.7 Duplicate Rows 16 4.8 Character Strings and Dates 16 4.9 Comparison Operators 16 4.10 Logical Operators 16 4.11 Character Functions 16 17 18

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission 4.12 Working with Dates 4.13 Types of Joins 4.14 Group Functions 20 4.15 Sub Queries 21 4.16 (DDL) 21 4.17 Views 22 4.18 Data Manipulation Language (DML) 23 4.19 Queries 26 4.20 One Possible Database State Corresponding to the 26 Company Scheme 30 4.21 Terminology Used in a 4.22 Sal Grade 30 33 5. FILE STRUCTURE 33

5.1 Records and Record Types 5.2 B-Trees and other Data Structures 5.3 DBMS 36 5.4 Existence Dependencies 40 43 6. GATE QUESTIONS 46

7. ASSIGNMENT QUESTIONS 51 

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission 1 THE ENTITY – RELATIONSHIP MODEL

1.1 INTRODUCTION 4) Performance monitoring. 5) Strategy design for and An entity is any object, place or activity recovery. about which an enterprise keeps data. It is 6) Authorization checks and validation an object which can have instances or procedures. occurrences. An entity type is a set of 7) Decides the information content. objects which share common properties. The Database Design consists of three 1.4 THE ENTITY RELATIONSHIP DIAGRAM components: Conceptual Design on the basis of requirements, Data Modeling 1.4.1 RELATIONSHIPS AND RELATIONSHIP (Entity – Relationship Diagrams and SETS Normalization), and Physical Design, and Implementation. The major step in A relationship expresses an association conceptual design is to identify entities and between entities. A relationship set is a set relationships, which reflect the data in a of relationships of the same type. A natural way. The aim of this step is to relationship may also have descriptive specify the conceptual structure of the data. attributes. For example, data (last data of This is known as data modeling. The Entity account access) could be an attribute of the – Relationship (E – R) model is used as an relationship set. information model to develop conceptual structure. 1.4.1.1 MAPPING CARDINALITIES

1.2 THE E – R MODEL It indicates the number of entities with which another entity can be associated via The E – R data model considers the real a relationship. The degree of relationship is world consisting of a set of basic objects called cardinality. and relationships among these objects. A a) One-to-one: An entity in A is associated number of attributes are associated with an with at most one entity in B, and an entity and the attributes describing it. The entity in B is associated with at most set of all entities or relationships of the one entity in A. same type is called the entity set or b) One-to-many: An entity in A is relationship set. associated with any number in B. An entity in B is associated with at least 1.3 DATABASE ADMINISTRATOR (DBA) one entity in A. c) Many-to-one (N:1): An entity in A is All controlling of a database system is done associated with at most one entity in B. by database administrator. An entity in B is associated with any number in A. 1.3.1 FUNCTIONS OF DBA 1.4.2 KEYS

1) Decides the storage structure and Differences between entities must be access strategy. expressed in terms of attributes known as 2) Creation of for keys. These facilitate us to uniquely identify statistical analysis. each entity in a set. 3) Responding to changes in requirements.

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission 1.4.3 SUPER KEY 1.4.7 AGGREGATION

It is a set of one or more attributes which The E – R model cannot express put together enable us to identify uniquely relationships among relationships. When an entity in the entity set. would we need such a thing? Consider a database with information 1.4.4 about employees who work on a particular A super key may contain extraneous project and using a number of machines for attributes, and we are often interested in doing that work. the smallest super key. A super key for We get the E-R diagram shown in Figure. which no subset is a super key is called a candidate key.

1.4.5 It is a candidate key (there may be more than one) chosen by the database designer to identify entities in an entity set. The idea of strong and weak entity sets is related to the existence dependencies such as the member of a strong entity set is a dominant entity, and the member of a weak entity set is a subordinate entity. A weak entity set does not have a primary key, but we need a means of distinguishing among the entities. Relationship sets Working and Uses could be combined into a single set. However, 1.4.6 GENERALIZATION they shouldn’t be, as this would obscure the logical structure of this scheme. The Generalization hides differences and solution is to use aggregation. It is an emphasizes similarities. Distinction is made abstraction through which relationships through attribute inheritance. are treated as higher – level entities. For Attributes of higher – level entity are our example, we can treat the relationship inherited by lower - level entities. set Working and the entity sets Employee and Project as a higher –level entity set called Working. Following figure shows the E-R diagram with aggregation.

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission Transforming an E-R diagram with aggregation into tabular form is easy. We can create a table for each entity and relationship set as before. The table for relationship set Uses contains a for each attribute in the primary key of Software Tool and Working.

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission 2 RELATIONAL MODEL

2.1 LEVELS OF A DATABASE SYSTEM 2.1.1 DOMAINS, ATTRIBUTES, TUPLE & RELATIONS The relational model represents the database as a collection of relations. A domain D is a set of atomic values. By Informally, each relation resembles at automatic we mean that each value in the stable of values or, to some extent, a “flat” domain is indivisible as far as the relational file of records model is concerned. A common method of specifying a domain is to specify a data type from which the data values forming the domain are drawn. It is also useful to specify a for the domain, to help in interpreting its values. Some examples of domains  USA – phone – numbers: The set of 10- digit phone numbers valid in the United States.  Social –security – numbers: The set of valid 9 – digit social security numbers.  Employee – ages: Possible ages of employees of a company; each must be a value between 15 and 80 years old.  Academic – department – names: The set of academic department names, such as computer Science, Economics, and Physics, in a university. Academic –department – codes: The set When a relation is thought of as a table of of academic department codes, such as CS, values, each in the table represents a ECON and PHYS, in a university. collection of related data values. In the The preceding is called logical definition of relational model, each row in the table domains. A data type or format is also represents a fact that typically corresponds specified for each domain. to real- world entity or relationship. The e. g. the data type for the domain USA- table name and column names are used to phone – numbers can be declared as a help Number, Class, Major –specify how to character string of the form (ddd)ddd – interpret the data values in each row, based dddd, where each d is a numeric (decimal) on the column each value is in. All values in digit and the first three digits form a valid a column are of the same data type. In the telephone area code. The data type for formal relational mode terminology, a row Employee – ages is an integer number is called a tuple, a column header is called between 15 and 80. For Academic – an attribute, and the table is called a department – names, the data type is the relation. The data type describing the types set of all character strings that represents of values that can appear in each column. valid department names. A domain is thus We now define these terms-domain, tuple, given a name, data type, and format. attribute, and relation- more precisely. Additional information for interpreting the

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission values of a domain can also be given; for Dom (Name) = Names; example, a numeric domain such as Person- Dom (SSN) = Social security numbers; weights should have the units of Dom(Home Phone) = measurement – pounds or kilograms. A Local_phone_numbers, relation scheme R, denoted by R(A1, Dom(Office Phone) = A2,…….An), is made of a relation name R and Local_phone_numberas, and a list of attributes A1, A2,……..An. Each Dom(GPA)= Grade_point_averages. attribute A1 is the name of a role played by A Relation (or relation state)2 r of the some domain D in the relation schema R. D relation schema R(A1, A2,…An), also is called the domain of Ai and is denoted by denoted by r(R), is a set of n_tuples r = (t1, dom(Ai) t2 _ tm. Each n_tuple t is an ordered list of n A relation schema is used to describe a values t = < v1, v2,…., vn>, where each value relation; R is a called the name of this vi, 1  i  n is an element of dom(Ai) or is a relation. The degree of a relation is the special null value. number of attributes n of its relation The ith value v, in tuple t, which schema. corresponds to the attribute Ai, is referred An example of a relation schema for a to as t[Ai]. The terms relation intension for relation of degree 7, which describes the schema R and relation extension for a university students, is given below relation state r(R) are also commonly used. STUDENT (Name, SSN, Homophone, Figure shows an example of a STUDENT Address, Office Phone, Age, GPA) relation, which corresponds to the STUDENT schema specified above. Each tuple in the relation represents a particular student entity. We display the relation as a table, where each tuple is shown as a row and each attribute corresponds to a column header indicating a role or interpretation of the values in that column. Null values represent attributes whose values are unknown or do not exist for some individual STUDENT tuples. The above definition of a relation can be restated as follows. A relation r(R) is a mathematical relation of degree n on the domains dom(A1), dom(A2),…., dom(An), which is a subset ofthe Cartesian product of the domains that define R: r (R)  (dom (A1). dom (A2)…..dom (An,)) The Cartesian product specifies all possible combinations of values from the underlying 2.2 THE ATTRIBUTES AND TUPLES OF A domains. Hence, if we denote the number RELATION STUDENT of values or cardinality of a domain D by 퐃 , and assume that all domains are For this relation schema, STUDENT is the finite, the total number of tuples in the name of the relation, which has seven Cartesian product is: |dom (A )|* | dom(A ) attributes. We can specify the following 1 2 *…….* dom (A ) | previously defined domains for some of the 2 Product of all these combinations, relation attributes of the STUDENT relation: state at a given time-the current Relation

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission state- reflects only the valid tuples that Given a body of data to be represented in a represent a particular state pf the real database, how do we decide on a suitable world. In general, as the state of the real logical structure for it. The required world changes, so does the relation, by relations and their attributes need to be being transformed into another relation specified. One approach is to design schemes state. However, the result of adding an that are in an appropriate normal form. attribute to represent new information that was not originally stored in the relation. 2.4.1 NORMAL FORMS (NF) It is possible for several attributes to have the same domain. The attributes indicate There are various types of NFs available. A different roles, or interpretations, for the relation is said to be in a particular normal domain e. g., in the STUDENT relation, the form only if it satisfies the constraint (that same domain Local-phone – number plays it contains atomic values only to be able to the role of Home phone, referring to the call it as in 1NF.) A number of normal forms “home phone of a student,” and the role of have been defined. Below is drawn a set- Office Phone, referring to the “office phone diagram of NFs. of the student,”

2.3 KEYS

2.3.1 PRIMARY KEYS

The term primary key is used to denote the candidate key that is chosen by the database designer as principle means of identifying entities within an entity set. e. g. attribute PART-NUMBER of the PART relation can be called as a primary key. Each PART tuple/row contains a distinct PART/NUMBER value, and this value may be used to distinguish that tuple from all 1st Normal Form others in the relation. Every relation will not have a single attribute primary key, but every relation ‘will’ have one another they must have unique identification of some Given a relation R, attribute A of R is kind. If the value of Primary key was null, it functionally dependent on attribute B of R, would be equivalent to saying that there if and only if, each A- value in R has exists some tuple that did not have any associated with it precisely one 3-value in unique identification. It was not R (at any instant of time). distinguishable from other touples. We Referring to our PARTS relation it can be enforce the NOT NULL and UNIQUE. seen that PARTS = (PART_NO, PART_NAME, PART_SIZE, QTY_ON_HAND), the attributes 2.4 RELATIONAL DATABASE DESIGN PART_NAME, PART_SIZE, QTY_ON_HAND of it are each functionally dependent on In general, the goal of database design is to attribute PART_No, because given a value generate a set of relation schemes that of PART_NO, there exists precisely one allow us to store information without corresponding value for each of redundancy, yet allow us to retrieve PART_NAME, PARTS_SIZE etc. Using information easily. symbols it is specified as,

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission PARTS. PART NO  PARTS.PART NAME S=(SUPLR_NO, SUPL_NAME, SUPL_STATUS, PARTS.PART_NO  PARTS.PART_SIZE CITY) PARTS.PART_NO  PARTS.QTY_ON_HAND It is supposed to maintain information on or more succinctly suppliers detailing, PARTS.PART_NO  PARTS. (PART_NAME, SUPLR_NO : Unique supplier code PART_SIZE, QTY_ON_HAND) SUPL_NAME : Name of supplier SUPL_STATUS : Numerical value The statement PART.PART_NO  Indicating quality and other services PARTS.PART_NAME (for example) is read provided by supplier w.r.t. city in which it as 'attribute PARTS.PART_NAME is is located functionally dependent upon attribute CITY : City where the supplier is PARTS.PART_NO' or equivalently, 'attribute located PARTS.PART_NO functionally determine In this relation S, the attribute, CITY is attribute PARTS. PART_NAME'. functionally dependent on the {SUPL_NO, NOTE that there is no requirement in the SUPL_STATUS}; however, it is not fully definition of functional dependence that a functionally dependent on this composite given X-Value appear in only one tuple of R. attribute because, of course, it is also functionally dependent on SUPLR_NO 2.4.1.1 FIRST NORMAL FORM alone. We will use this concept of full functional dependence while we discuss A relation is said to be in the 1st normal the normal forms on next page. form if every attribute is functionally dependent on the key. 2.4.1.2 SECOND NORMAL FORM (2NF) First normal form (1NF) is now To be in 2NF, a table must be in first considered to be part of the formal normal form and no attributes of the table definition of a relation in the basic (flat) should be functionally dependent on only relational model; historically, it was one part of a concatenated primary key. In defined to disallow multi valued attribute, other words, a relation R is in second composite attributes, and their normal form (2NF) if and only if it is 1NF combinations. It states that the domain of and every non key attribute is fully an attribute must include only atomic dependent on the primary key. (simple, indivisible) values and that the e. g. let`s consider ORDER_ITEM relation, value of any attribute in a tuple must be a ORDER_ITEM (ORD_NO, ITEM_NAME, QTY, single value form the domain of that ITEM_PRICE) attribute. Hence, 1NF disallows having a set This relation lists the items contained of values, a tuple of values, or a within various orders, the quantity of each combination of both as an attribute value associated with the order and their unit for a single tuple. In other words, 1 NF prices. disallows “relations within relations” or The key is formed as a combination of relations as attribute of tuples.” The only (ORD_NO + ITEM_NAME), the table is in attribute values permitted by 1NF are 1NF. It is not in 2NF, because ITEM_PRICE single atomic (or indivisible) values. is not functionally dependent on the ORD_NO component of the key. It is FULL FUNCTIONAL DEPENDENCE dependent only on the ITEM_NAME component. QTY is dependent on both Attribute B is fully functionally dependent parts of the key. To achieve 2NF form of on attribute A, if and only if, it is this relation, we decompose the functionally e.g., Take a relation S, ORDER_ITEM relation in,

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission ORDERJTEM (ORD_NO, ITEM_NAME, QTY) As can be seen, it is possible to specify the ITEM (ITEM_NAME, ITEM_PRICE) grade of a librarian just by knowing As we can see in a new 2NF set of relations, LIBRARIAN_NO and irrespective of it is now possible to add a new item details whether the librarian has issued any book irrespective of whether an order is placed or not. on it or not. If unit price of an item, ITEM_PRICE changes for a particular item then, only ITEM relation needs to be undated, effectively making less number of price updates per occurrence of an ITEM_DETAIL.

2.4.1.3 (3 NF) TRANSITIVE DEPENDENCE

If attribute A depends on B and B depends on C, due to which A depends on C, then A is said to be transitively dependent on C. Transitive dependency causes problems in updating.

Third Normal Form (3NF)

To be in 3NF, a table must be in 2NF and no attribute of the table should be transitively functionally dependent on the primary key. Let us consider a relation, BORROW, related to library management, BORROW= (BOOK_NO, PERSON_NO, DURATION, LIBRARIAN_NO, LIBRARIAN_GRADE) This relation lists books issued from various local libraries, for which duration the book was issued, the staff member of Table: Summary of Normal Forms Based the librarian who signed out the book and on Primary Keys and Corresponding grade of that librarian. To identify the Normalization issued books records/tuples, the key used is (BOOKJ_NO + PERSON_NO). Above 2.5 NETWORK DATA MODELING relation is in 2NF but not in 3NF. This is CONCEPTS because LIBRARIAN_GRADE is only transitively dependent on LIBRARIAN_NO There two basic data structures in the and not dependent on network model: records and sets. (BOOK_NO+PERSON_NO). It is functionally dependent on identity of Records, Record Types, and Data Items librarian. So, we decompose the relation as, Data is stored in records; each record BORROW =(BOOK_NO, PERSON_NO, consists of a group of related data values. DURATION, LIBRARIAN_NO) Records are classified into record types, LIBRARIAN=(LIBRARIAN_NO,IBRARIAN_GR where each record type describes the ADE) structure of a group of records that store

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission the same type of information. We give each ADDRESS record type a name, and we also give a MAJORMDEPT name and format (data type) for each data BIRTHDATE item (or attribute) in the record type figure Format 4 shows a record type STUDENT with data CHARACTER 30 items NAME, SSN, ADDRESS, MAJORDEPT CHARACTER 9 & BIRTHDATE. CHARACTER 40 We can declare a virtual data item (or CHARACTER 10 derived attribute) AGE for the record type CHARACTER shown in Figure 4 and write a procedure to calculate the value of AGE from the value of the actual data item BIRTHDATE in each record. A typical has numerous types–from a few to a few hundred. To represent relationships between records, the networks model provides the modeling construct called set type which we discuss next.

2.5.1 SET TYPES AND THEIR BASIC PROPERTIES

A set type is a description of a 1: N relationship between two record types. Figure 5 shows how we represent a set type diagrammatically as an arrow. This type of diagrammatic representation is called a Bachman diagram. Each set type definition consists of three basic elements:-  A name for the set type.  An owner record type. The set type in Figure is called  A member record type. MAJOR_DEPT, DEPARTMENT is the owner record type, and STUDENT is the member record type. This represents the 1: N relationship between academic departments and students majoring in those Data item name departments. In the database itself, there will be many set occurrences (or set instances) corresponding to a set type. Each instance relates one record from the owner record type DEPARTMENT record in our example to the set of records from the member record type related to it the set of STUDENT records for students who major in that department. Hence, each set occurrence is composed of NAME • One owner record from the owner SSN record type.

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission • A number of related member records ‘computer Science’ set, and that of (zero or more) from the member record ‘Kareem Rashad’ is the last member type. A record from the member record record. The set of the network model is type cannot exist in more than one set sometimes referred to as an owner- occurrence of a particular set type. This coupled set or co-set, to distinguish it maintains the constraint that a set type from a mathematical set represents a 1:N relationship. In our example a STUDENT record can be related to at most one major DEPARTMENT and hence is a member of at most one set occurrence of the MAJOR DEPT set type. A set occurrence can be identified either by the owner record or by any of the member records. Figure 6 shows four set occurrences (instances) of the MAJDR-DEPT set type. Notice that each instance must have one owner record but can have any number of member records (zero or more). Hence, we usually refer to a set instance by its owner record. The set instances in Figure 6 can be referred to as the `Computer Science`, `Mathematics`, `Physics`, and `Geology` sets. It is customary to use a different representation of a set instance (Figure 7) where the records of the set instance are shown linked together by pointers, which corresponds to a commonly used technique for implementing sets. In the network model, a set instance is not identical to the concept of a set in mathematics. There are two principal differences:-  The set instance has one distinguished element the owner record_ whereas in a mathematical set there is no such distinction among the elements of a set.  In the network model, the member records of a set instance are ordered, whereas order of elements is immaterial in a mathematical set. Hence, we can refer to the first, second, ith, and last member records in a set instance. Figure 7 shows an alternate “linked” representation of an instance of the set MAJOR_DEPT. In figure 7 the record of `Manual Riverva` is the first STUDENT(member) record in the

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission 3 TRANSACTIONS

3.1 TRANSACTIONS: component of the database system called the concurrency-control component. Collections of operations that form a single logical unit of work are called transactions. 3.1.2 TRANSACTION STATE

3.1.1 TRANSACTION CONCEPT A transaction may not always complete its execution successfully such a transaction is A transaction is a unit of program termed aborted. Any changes that the execution that accesses and possibly aborted transaction made to the database updates various data items. To ensure must be undone. integrity of the data, we require that the Once a transaction has committed, we database system maintains the following cannot undo its effects by aborting it. The properties of the transactions: only way to undo the effects of a committed If the database is consistent before an transaction is to execute a compensating execution of the transaction, the . remains consistent after the execution of the transaction. Ensuring consistency for Active, the initial state; the transaction an individual transaction is the stays in this state while it is executing responsibility of the application programmer Partially committed, after the final who codes the transaction. statement has been executed Ensuring atomicity is the responsibility of Failed, after the discovery that normal the database system itself; specifically, it is execution can no longer proceed handled by a component called the Aborted, after the transaction has been transaction-management component. rolled back and the database has been The durability property guarantees that, restored to its state prior to the start of the once a transaction completes successfully, transaction all the updates that it carried out on the Committed, after successful completion database persist, even if there is a system failure after the transaction completes A transaction is said to have terminated if execution. has either committed or aborted, since the Ensuring durability is the responsibility of actual output may still be temporarily a component of the database system called residing in main memory. the recovery management component. If several transactions are executed 3.1.3 IMPLEMENTATION OF ATOMICITY concurrently, their operations may interleave AND DURABILITY in some undesirable way, resulting in an inconsistent state. The recovery-management component of a The isolation property of a transaction database system implements the support ensures that the concurrent execution of for atomicity and durability. We first transactions results in a system state that is consider a simple, but extremely inefficient, equivalent to a state that could have been scheme. This scheme assumes that only one obtained had these transactions executed transaction is active at a time, and is based one at a time in some order. Ensuring the on making copies of the database, called isolation property is the responsibility of a shadow copies. The scheme assumes that the database is simply a file on disk. A

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission pointer called db-pointer is maintained on schemes. Suppose that the two transactions disk; it points to the current copy of the are executed one at a time in the order T1 database. In the shadow-database scheme, followed by T2. a transaction that wants to update the The execution sequences just described are database first creates a complete Copy of called schedules. They represent the the database. All updates are done on the chronological order in which instructions new database copy, leaving the original are executed in the system. copy, called the shadow copy, untouched. These schedules are serial. Each serial If at any point the transaction has to be schedule consists of a sequence of aborted, the new copy is merely deleted. instructions from various transactions, The old copy of the database has not been where the instructions belonging to one affected. On UNIX systems, the flush single transaction appear together in that command is used of this purpose. schedule. Thus, for a set of n transactions, The transaction is said to have been there exist n! different valid serial schedules. committed at the point where the updated With multiple transactions, the CPU time is db-pointer is written to disk. We can abort shared among all the transactions. In the transaction by deleting simply the new general, it is not possible to predict exactly copy of the database. how many instructions of a transaction will be before the CPU switches to another 3.1.4 DISADVANTAGE transaction. Thus, the number of possible schedules for a set of n transactions is Since executing a single transaction much larger than n! requires copying the entire database. Furthermore, the implementation does not 3.2 SERILIZABLE SCHEDULE allow transactions to execute concurrently with one another. If a concurrent schedule is equivalent to any of the serial schedule it is said to be a 3.1.5 CONCURRENT EXECUTIONS serializable schedule and this property is known as serializability. Ensuring consistency in spite concurrent It is the job of database system to ensure execution of transactions requires extra that any schedule that gets executed will work; it is far easier to insist that leave the database in a consistent state. transactions run serially-that is, one at a Any schedule that executed has the same time, each starting only after the previous effect as a schedule that could have one has completed. There are two good occurred without any concurrent execution. reasons for allowing concurrency. There is The schedule should, in some sense, be an increase in the throughput of the system equivalent to a serial schedule. – that is, in the number of transactions that can be executed in a given amount of time. 3.2.1 SERIALIZABILITY The processor and disk utilization also increase. Concurrent execution reduces the The database system must control average response time: the average time concurrent execution of transactions, to for a transaction to be completed after it ensure that the database state remains has been submitted. The database system consistent. must control the interaction among the concurrent transactions to prevent them 3.2.2 CONFLICT SERIALIZABILITY from destroying the consistency of the database. It does so through a variety of If Ii and Ij refer to the same data item Q, mechanisms called concurrency-control then the order of the two steps may matter.

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission Ii = read (Q), Ij = read (Q). Returning to our previous examples, we Since the result of only the later of the two note that schedule 1 is not equivalent write instruction is preserved. to schedule 2, since, in schedule 1, the value However, the value obtained by the next of account A read by transaction T2 was read (Q) instruction of S is affected. If there produced by T1, whereas this case does not is no other write (Q) instruction after Ii and hold in schedule 2. Ij in S, then the order Ii and Ij directly affects A schedule S is view serializable if it is view the final value of Q in the database state equivalent to a serial schedule that results from schedule S. Every conflict – serializable schedule is We say that Ii and Ij conflict if they are view serializable, but there are view- operations by different transaction on the Inserializable schedules that are not same data item, and at least one of these conflict serializable. Since every pair of instructions is a write operation. consecutive instructions conflicts, blind Do not conflict, we can swap the order of Ii writes appear in any view – serializable and Ij to produce a new schedule S’. schedule that is not conflict serializable. Schedules 3 and 5 both produce the same final system state. 3.3 RECOVERABILITY No conflicting instructions as follows: If a schedule S can be transformed into a In a system that allows concurrent schedule S’ by a series of swaps of no execution, it is necessary also to ensure conflicting instructions, we say that S and S’ that any transaction Tj that is dependent on are conflict equivalent. Ti is also aborted. The concept of conflict equivalence leads to the concept of conflict serializability. We 3.4 RECOVERABLE SCHEDULES say that a schedule S is conflict serializable if it is conflict equivalent to a serial Most database system requires that all schedule. schedules be recoverable. A recoverable This schedule is not conflict serializable, schedule is one where, for each pair of since it is not equivalent to either the serial transactions Tj and Tjsuch that Tj reads a schedule or the serial schedule data items previously written by Ti, the . operation of Ti appears before the The write (B) instruction of T5 conflicts commit operation of Tj. with the read (B) instruction of T1. For the system to determine that schedule 3.5 CASCADE LESS SCHEDULES 8 produces the same outcome as the serial schedule , it must analyze the A single transaction failure leads to a series computation performed by T1 and T5, of transaction rollbacks, is called cascading rather than just the read and write rollback. Cascading rollback is undesirable, operations. since it leads to the undoing of a significant amount of work. It is desirable to restrict 3.2.3 VIEW SERIALIZABILITY the schedules to those where cascading rollbacks cannot occur. Such schedules are The schedules S and S’ are said to be view called cascade less schedules. Tj reads a equivalent if the following three conditions data item previously written by Ti, the are met: Conditions 1 and 2 ensure that commit operation of Ti appears before the each transaction reads the same values in read operation of Tj. It is easy to verify that both schedules and, therefore, performs the every cascade less schedule is also same computation. recoverable.

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission 3.6 IMPLEMENTATION OF ISOLATION Thus, to test for conflict serializability, we need to construct the precedence graph Specifically, schedules that are conflict or and to invoke a cycle – detection algorithm. view serializable and cascade less satisfy these requirements. The goal of 3.9 TESTS FOR VIEW SERIALIZABILITY concurrency–control schemes is to provide a high degree of concurrency, while Testing for view serializability is ensuring that all schedules that can be computationally an expensive problem. generated are conflict or view serializable, And at least one of these transactions and are cascade less. writes. The write (Q) instructions of T3 and T4 are 3.7 TRANSACTION DEFINITION IN SQL called useless writes. We need to develop a scheme for deciding whether an edge needs If a program terminates without either of to be inserted in a precedence graph. A these commands, the updates are either labeled precedence graph. We therefore committed or rolled back. require that any schedule produced by The definition of serialize used by the concurrent processing of a set of standard is that a schedule must have the transactions will have an effect equivalent same effect as would a serial schedule. to a schedule produced when these The levels of consistency specified by SQL - transactions are run serially in some order. 92 are as follows: A system that guarantees this property is Allows only committed records to be read, said ensures serializability. We can test a and further requires that, between two given schedule for conflict serializability by reads of a record by a transaction, no other constructing a precedence graph for the transaction is allowed to update the record. schedule; we can test for view Allows only committed records to be read, serializability in order 2n time by may have been updated by other constructing a labeled precedence graph committed transactions.` Allows even and searching over all possible distinct uncommitted records to be read. labeled graphs for a graph with a cycle.

3.8 TESTING FOR SERILAZABILITY

When designing concurrency control schemes, we must show that schedules generated by the scheme are serializable. To do that, we must first understand how to determine, given a particular schedule S, whether the schedule is serializable. In this section, we shall present methods for determining conflict and view serializability. We will show that there exists a simple and efficient algorithm to determine conflict serializability. However, there is no efficient algorithm for determining view serializability. If the precedence graph for S has a cycle, then schedule S is not conflict serializable. If the graph contains no cycles, then the schedule S is conflict serializable.

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission 4 QUEL 4.1 QUEL 4.4 SQL

QUEL is the in the system SQL allows you to communicate with the INGRES. QUEL is based on . database and has the following advantages: The fundamental aspect of the languages  Efficient based on relational calculus is tuple variable  Easy to learn and use (which is a variable that "rangers over""  Functionally complete (SQL allows you some named relation). to define, retrieve, and manipulate data e.g., the query "Get supplier numbers for in the tables). suppliers in London" can be expressed in SQL is a English – like language and can be QUEL as: used by a range of users, including those RANGE of SX is S with little or no programming experience. RETRIEVE (SX. S#) where SX. CITY = It is a non – procedural language. It reduces 'LONDON'. the amount of time required for creating The tuple here is SX that ranges over and maintaining systems. SQL statements relation S. are not case sensitive. The statements can be written on one or more lines. Keywords cannot be abbreviated or split across lines 4.2 SEQUEL and clauses are usually placed on separate lines for readability & ease of editing. In SEQUEL, the expression followi ng For executing a SQL statement places a WHERE can be any expression involving semicolon (;) at the end of the last clause. the attributes of the relation following Statement Description FROM, arithmetic comparisons and SELECT Retrieves data from the database. operations. Boolean connectives (AND.K INSERT Enters new rows, change OR NOT), set operations (UNION, UPDATE existing rows, and removes INTERSECT, MINUS), DELELE unwanted rows from tables set membership (X INS, where S is a set or in the database, equivalently S CONTAINS X) and the respectively. Collectively known as data negation of set membership (X NOT IN S manipulation Language OR S DOES NOT CONTAIN X). (DML) When SEQUEL applies a mapping it does CREATE Sets up, changes, and not eliminate duplicates unless told to do ALTER DROP removes data structures so by the keyword UNIQUE. In SEQUEL, RENAME from tables. Collectively TRUNCATE known as data definition assignment is indicated by preceding a Language (DDL). query by ASSIGN TO R COMMIT Manages the changes made ROLLBACK by DML statements. 4.3 ASSIGN TO R: Changes to the data can he grouped together into logical transactions. To assign the result to relation R. Any GRANT Gives or removes access relational algebra expression in SEQUEL REVOICE rights to both the Oracle can be evaluated by applying one operator database and the structures at a time and thereby computing each sub within it Collectively known expression, hence SEQUEL is complete. as (DCL).

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission 4.5 SELECT STATEMENT DEPTNO DNAME LOC ------A statement retrieves information 10 ACCOUNTING NEW YORK 20 RESEARCH DALLAS from the database. Using a SELECT 30 SALES CHICAGO statement, you can do the following: 40 OPERATIONS BOSTON You can display all columns of data in a 4.5.1 SELECTION table by following the SELECT keyword with an asterisk (*). You can use the selection capability in SQL to choose the rows in a table that you want 4.5.4 SELECTING SPECIFIC COLUMNS, returned by a query. You can use various ALL ROWS criteria to selectively restrict the rows that you see. You can use the SELECT statement to display specific columns of the table by 4.5.2 PROJECTION specifying the column names, separated by commas. You can use the projection capability in SQL to choose the columns in a table that you 4.6 DEFINING A NULL VALUE want returned by your query. You can choose as few or as many columns of the If a row lacks the data value for a particular table as you require. column, that value is said to be null, or to contain null. A null value is a value that is 4.5.3 JOIN unavailable, unassigned, unknown, or inapplicable. A null value is not the same as You can use the join capability in SQL to zero or a space. Zero is a number, and a bring together data that is stored in space is a character. different tables by creating a link between them. In its simplest form, a SELECT 4.7 DUPLICATE ROWS statement must include the following:  A SELECT clause, which specifies the The default display of queries is all rows, column to be displayed including duplicate rows  A FROM clause, which specifies the To eliminate duplicate rows in the result, table containing the columns listed in include DISTINCT keyword in the SELECT the SELECT clause. clause immediately after the SELECT SELECT [DISTINCT] {*, column keyword. [],………..} FROM table 4.8 CHARACTERS STRINGS AND DATES

In the Syntax:  Character strings and date values are SELECT : is a list of one or more columns enclosed in single quotation marks. FROM identifies which tables  Character values are case sensitive and DISTINCT suppresses duplicates date values are format sensitive. * selects all columns  Number values are not enclosed within Column selects the named column quotation marks. Alias gives selected columns different headings 4.9 COMPARISON OPERATORS FROM table specifies the table containing the columns Comparison operators are used in Select All Columns, All Rows FROM dept; conditions that compare one expression to

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission another. They are used in the WHERE WHERE dname LIKE ‘%\_%’ ESCAPE ‘\’; clause in the following format: The ESCAPE option identifies the backslash (\) as the escape character. Operator Meaning = Equal to 4.9.4 USING THE IS NULL OPERATOR > Greater than >= Greater than equal to The IS NULL operator tests for values that < Less than are null. A null value means the value is <= Less than or equal to unavailable, unassigned, unknown, or <> Not equal to inapplicable. Therefore, you cannot test with (=) because a null value cannot be 4.9.1 THE BETWEEN OPERATOR equal or unequal to any value.

You can display rows based on range of SELECT ename, mgr values using the BETWEEN operator. The FROM EMP range that you specify contains a lower WHRER mgr IS NULL; range and an upper range. Values specified with the BETWEEN operator are inclusive. 4.10 LOGICAL OPERATORS

4.9.2 THE IN OPERATOR A logical operator combines the result of two component conditions to produce a To test for values in a specified list, use the single result based on them or to invert the IN operator. The IN operator can be used result of a single condition. Three logical with any data type. If characters or dates operators are available in SQL. are used in the list, they must be enclosed  AND in single quotation marks (‘’).  OR  NOT 4.9.3 THE LIKE OPERATOR Operator Meaning You can select rows that match a character AND Returns TRUE if both component conditions are TRUE pattern by using the LIKE operator. The OR Returns TRUE if either component character pattern – matching operation is conditions are TRUE referred to as a wildcard search. Two NOT Returns TRUE if the following symbols can be used to construct the conditions is FALSE search string. 4.10.1 RULES OF PRECEDENCE Symbol Description % Represents any sequence Order Operator of zero or more characters Evaluated - Represents any single 1 All comparison operators character 2 NOT 3 AND When you need to have exact match for the 4 OR actual ‘%’ and ‘- ‘characters, use the Override rules of precedence by using ESCAPE option. This option specifies what parentheses. the ESCAPE character is. If you have HEAD QUARTERS as a department name, you 4.10.2 THE ORDER BY CLAUSE would search for it using the following SQL statement: The ORDER BY clause can be used to sort SELECT * FROM dept

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission the rows. SELECT expr INITCAP Syntax INITCAP (column : FROM table expression) [WHRER condition(s)] Purpose Converts alpha character values to uppercase for the [ORDER BY {column, expr} first character of each word, [ASC| DESC]]; all other letters in lowercase. Example SELECT INITCAP (‘ORACLE’) In the syntax “Mix” FROM dual; Output Mix ORDER BY specifies the order in which the ______retrieved rows are displayed. Oracle ASC orders the rows in ascending order CONCAT Syntax CONCAT (column : expression1, (this is the default order). column2: expression) DESC orders the rows in descending order. Purpose Concatenates the first character value to the second character value; i) Single-Row Functions equivalent to concatenation These functions operate on single rows | | operator   only and return one result per row. There | | are different types of single – row functions. Example CONCAT (‘Good’, String’) Output Good String  Character  Number SUBSTR Syntax SUBSTR (column : expression, m, [n])  Date Purpose Returns specified characters  Conversion from character values starting at character position ii)Multiple –Row Functions m, n characters long (If m is negative, the count starts These functions manipulate groups of rows from the end of the to give one result per group of rows. character value. If n is omitted, all characters to the 4.11 CHARACTER FUNCTIONS end of the string are returned.) Number Functions Example SUBSTR (‘String’, 1,3) Output Str LOWER Syntax LOWER (column : LENGTH Syntax LENGTH (column : expression) expression) Purpose Converts alpha character Purpose Returns the number of values to lowercase characters in value Example SELECT LOWER (‘ORACLE’) Example LENGTH (‘String’) “Lower” FROM dual; Output 6 Output Lower INSTER Syntax INSTR (column : expression, m) ______Purpose Returns the number of Oracle character in value UPPER Syntax UPPER (column : Example INSTR (‘String’, ‘r’) expression) Output 3 Purpose Converts alpha character vales to uppercase LPAD Syntax LPAD (column : expression, Example SELECT LOWER (‘ORACLE’) n, ‘string’ “Upper” FROM dual; Purpose Pads the character value Output Lower right – justified to a total width of n character ______positions Oracle

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission Example LPAD (sale, 10, ‘*’) Purpose Returns the smallest Output ******5000 integer that is greater TRIM Syntax TRIM (leading : trailing: both, than or equal to a specific value. trim character FROM trim source) Example CEIL (1.3) Purpose Enables you to trim leading CEIL ( -2.3) or trailing character (or Output 2 both) from a character -2 string. If trim character or trim source is a character FLOOR Syntax FLOOR (column : literal, you must enclose it in expression) single quotes. Purpose FLOOR is intuitive opposite of CEIL. Example (‘S’ FROM ‘SMITH’) Example FLOOR (1.3) FLOOR (-2.3) Output MITH Output 01-Mar LTRIM Syntax LTRIM (string [,’set’]) MOD Syntax MOD (m,n) Purpose The function trims off Purpose Returns the remainder of unwanted characters from m divided by n the left end of the string. Example MOD (-30,7) String is the name of the MOD (4.1, .3) column, literal string Output -2 0.2 Set is the collection of POWER Syntax POWER (value, characters you want to exponent) trim off. If no set of Purpose Raise the value to a given characters is specified, the exponent function trims off spaces. Example POWER (3,3) Example LTIRM (‘OAORACLE’, ‘OA’) Output 27 Output ORACLE ROUND Syntax ROUND (column : RTRIM Syntax RTRIM (string [, ‘set’]) expression, n) Purpose Rounds the column, Purpose The function trims off expression, or value to n unwanted characters from decimal places or if n is the right end of the string. an omitted, no decimal String is the name of the place. If n is negative, column, literal string. Set number to left of the is the collection of decimal points are characters you want to rounded. trim off. If no set of Example ROUND (45.926,2) characters is specified, the function trims off spaces. Output 45.93 Example RTIRM (‘ORACLE.”.’,’. “ ‘) SQRT Syntax SQRT (column : Output ORACLE expression) Purpose Returns the square root of the given number. The number must be positive, ABS Syntax ABS (column : because square root of expression) negative number is an Purpose Returns the Absolute imaginary number. value of expression or Example SQRT (64) column Example ABS (-30) Output 8 Output 30 TRUNC Syntax TRUNC (column : expression, n) CEIL Syntax CEIL (column : Purpose Truncates the column, expression) expression or value to n

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission decimal places or if n is Finds the number of omitted, no decimal months between date1 places. If n is negative, and date2. If date 1 is numbers left of the later than date2, the decimal point are result is positive; if truncated to zero. Purpose date1 is earlier than Example TRUNC (45.926,2) date2, the result is Output 45.92 negative. The non- integer part of the result represents a portion of 4.12 WORKING WITH DATES the month. MONTHS_BETWEEN The dates are stored in an internal numeric Example (’01 – SEP-95’,’11-JAN- format, representing the century, year, 94’) month, day, hours, minutes and seconds. Output 19.6774194 ADD_MON ADD_MONTHS (date, Syntax THS ‘char’) 4.12.1 SYSDATE Adds n number of calendar months to date. SYSDATE is a date function that returns the Purpose The value of n must be current date and time. You can use an integer and can be SYSDATE just as you would use any other negative. Adds n number of column name. For example, you can display calendar months to date. the current date by selecting SYSDATE Purpose The value of n must be from a table. an integer and can be negative. ADD_MONTHS (’11-JAN- 4.12.1.1 SELECT SYSDARE FROM DUAL; Example 94’, 6) Using Arithmetic Operators with Dates: Output 11-Jul-94 NEXT_DA NEXT_DAY (date, Syntax Since the database stores dates as Y ‘char’) numbers, you can perform calculations Finds the date of the using arithmetic operators such as addition next specified day of the and subtraction. You can perform the week (‘char’) following following operations: Purpose date. The value of char may be a number representing a day of a Operation Result Description character string. Date + Date Adds a number of NEXT_DAY (’01-SEP-95’, Example number days to a date ‘FRIDAY’) Date - Date Subtracts a Output 08-Sep-95 number number of days LAST_DAY Syntax LAST_DAY (date) from a date Finds the date of the last Date-Date Number Subtract one date Purpose day of the month that of days from another contains date. Date A- Date Adds a number of Example LAST_DAY (’01-SEP-95’) number / 24 hours to a date Output 30-Sep-95 ROUND Syntax ROUND (date[,’fmt’]) 4.12.1.2 Date Functions Returns date rounded to the unit specified by the format model fmt. If the MONTHS_ MONTHS_BETWEEN Purpose Syntax format model fmt is BETWEEN (date1, date2) omitted, date is rounded to the nearest day.

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission ROUND (’25-JUL- Example Syntax: 95’,’MONTH’) SELECT table. Column, table2. ROUND (’25-JUL- Column FROM table 1, table2 95’,’YEAR’) 01-Aug-95 WHERE Output 01-Jan-96 table1.column1=table2.column2; TRUNC Syntax TRUNC (date [,’fmt’]) If the same column name appears in more Returns date with the than one table, the column name must be time portion of the day prefixed with the table name. truncated to the unit specified by the format Purpose 4.13 TYPES OF JOINS model fmt. If the format model fmt is omitted, date is truncated to the There are two main types of join nearest day. conditions: TRUNCATE (’25-JUL-  Equijoin 95’,’MONTH’) Example  Non – equijoin TRUNCATE (’25-JUL- 95’,’YEAR) 01-Jul-95 4.13.1 Additional join methods include Output 01-Jan-95 the following:  Outer join Explicit Data type Conversion:  Self join  Set operators SQL provides three functions to convert a value from one data type to another. 4.13.1.1 Set Operators Function Purpose TO_CHAR(number | Converts a number or Set operators combines results of two date [fmt]) date value to a VARCHAR2 character queries into a single result. Set operations string with format mode are generally performed on two Lists ‘fmt’. obtained from distinct tables. TO_NUMBER(char Converts a character [fmt]) string containing digits Operator Description to a number in the UNION All distinct rows selected by format specification by either query the optional format UNION ALL Rows selected by either query, model ‘fmt’. including all duplicates. TO_DATE(char [fmt]) Converts a character INTERSECT All distinct common rows string representing a selected by both date to a date value queries. according to the ‘fmt’ MINUS All distinct rows selected by the specified. If ‘fmt’ is first query but not by omitted, the format is the second DD-MM-YY. 4.12.1.3 DISPLAYING DATA FROM 4.14 GROUP FUNCTIONS: MULTIPLE TABLES Unlike single-row functions, group functions When data from more than one table in the operate on sets of rows to give one result data base is required, a join condition is per group. The sets may be the whole table used. Rows in one table can be joined to or the table split into groups. rows in another table according to common values existing in corresponding columns, 4.14.1 TYPES OF GROUP FUNCTIONS that is, usually primary & columns.

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission Function Description (ii) Multiple –row Subqueries: VG ([DISTINCT : ALL]n) Average value of n, Queries that return more than one row ignoring null values from the inner SELECT statement. COUNT ({*:[DISTINCT: Number of rows, ALL]expr}) where naps evaluates (iii)Multiple – column Sub queries: to something other Queries that return more than one than null (Count an column from the inner SELECT selected rows using*, statement. including duplicates and rows with nulls) MAX ([DLSTINCT: Maximum value of 4.15.1.1 Single –Row Sub queries ALL]expr}) expr, ignoring null values A single – row sub query is one that returns MIN ([DISTINCT: Minimum value of one row from the inner SELECT statement. ALL]expr) min, ignoring null This type of sub query uses a single – row values operator. SUM ([DISTNCE: ALL]n) Sum values of n, ignoring null values HAVING Clause with Sub queries STDDSV ([DISNCT:|ALL]n) Standard deviation of You can use sub queries not only in the lapin-Mg null values WHERE clause, but also in the HAVING VARIANCE ([DISTINCT Variance of n, clause. The Server executes the sub query, :ALL]n) ignoring null values and the results are retuned into the HAVING clause of the main query. The COUNT function has two formats: SELECT deptno, MIN (Sal)  COUNT (*) FROM emp  COUNT (expr) GROUP BY deptno COUNT (*) returns the number of rows in a HAVING MIN (Sal) > table, including duplicate rows and rows SELECT MIN (Sal) containing null values in any of the FROM emp columns. WHERE deptno = 20); COUNT (*) returns the number of rows satisfies the condition in the WHERE clause 4.15.1.2Multiple – Row Sub queries SELECT COUNT (*) FROM emp Sub queries that return more than one row WHERE deptno = 30; are called multiple – row sub queries. You COUNT (expr) returns the number of non use a multiple – row operator, instead of null rows in the column identified by expr. single – row operator, with a multiple – SELECT COUNT (comm.) row sub query. The multiple – row FROM emp operator expects one or more values. WHERE deptno = 30; Operator Meaning 4.15 SUB QUERIES IN Equal to any member in the list ANY Compare value to each value The inner query or the sub query returns a returned by the sub query value that is used by the outer query or the All Compare value to every value returned by the sub query main query. Example 5.2 4.15.1 TYPES OF SUBQUERIES Find the employees who earn the same salary as the minimum salary for (i) Single – row Subquereis: departments. Queries that return only one row form SELECT ename, Sal, deptno the inner SELECT statement. FROM emp

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission WHERE Sal IN WHERE expr1 = (SELECT MIN (Sal) alias.expr2) FROM emp GROUP BY deptno); Example 5.3 The inner query is executed first, SELECT ename, sal, deptno FROM emp 4.15.1.3 Multiple – Column Sub queries WHERE deptno = e.deptno);

If you want to compare two or more 4.16 Data Definition Language (DDL) columns, you must write a compound WHERE clause using logical operators. 4.16.1 DATABASE OBJECTS Multiple –column sub queries enable you to combine duplicate WHERE conditions into A database can contain multiple data a single WHERE clause. structures. Each structure should be Syntax outlined in the database design so that it SELECT column, column, can be created during the build stage of FROM table database development. WHERE (column, column...) IN (SELECT column, column, 4.16.2 THE CREATE TABLE STATEMENT FROM table WHERE condition); Create tables to store data by executing the SELECT empno, mgr, deptno SQL, ‘CREATE TABLE’ statement. This FROM emp statement is one of the data definition WHERE (mgr,deptno) IN language (DDL) statements. (SELECT mgr, deptno Syntax FROM emp CREATETABLE [schema.] table WHERE ename =’ MARTIN’) (column data type [DEFAULT AND ename<> ‘MARTIN’; expr][,…..]);

4.15.1.4 CORRELATED SUBQURIES In the syntax Schema Is the same as the owner’s name The Server performs a correlated sub Table Is the name of the table query when the sub query references a DEFAULT expr Specifies a default value if a column from a table referred to in the value is omitted in the INSERT Statement parent statement. A correlated sub query is Column Is the name of the column evaluated once for each row processed by Data type Is the column’s datatype and the parent statement. The parent statement length can be a SELECT, UPDATE or DELETE statement. The Server performs a 4.16.3 DATATYPES correlated sub query when the sub query references a column from table in the Data type Description parent query. VARCHAR2 Variable-length character data (A Syntax (size) maximum size must be specified. Default and minimum size is 1. SELECT column1, column2, ……. Maximum size is 4000) FROM table1 alias CHAR (size) Fixed - length character data of WHERE column1, operator length size bytes (Default and (SELECT column1, minimum size Is 1. Maximum size column2……… is 2000) NUMBER(p, Number having precision p and FROM table2 s) scales.(The precision is the total

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission number of decimal digits and the scale is the number of digits to the 4.16.5.1 Add a Column right of the decimal point. The precision can range from 1 to 38 You can add columns to a table by using the and the scale can range from 84 to ALTER TABLE statement with the ADD 127.) clause. DATE Date and time values between January 1, 4712 B.C. and December ALTER TABLE 31, 9999 A.D. ADD (column data type [DEFAULT LONG Variable-length character data up expr] to 2 gigabytes. [, column data type]…..); CLOB Single-byte character data up to 4 gigabytes. RAW (size) Paw binary dam of length of size 4.16.5.2 Modify a Column (Size must be specified Maximum size 2000). You can modify existing columns in a table LONG RAW Raw binary data of variable length by using the ALTER TABLE statement with up to 2 gigabytes. the MODIFY clause. Column modification BLOB Binary dam up to 4 gigabytes. can include changes to a column’s data BBILE Binary data stored in an external file; up 4 gigabytes. type, size and default value.

4.16.4 CREATING A TABLE BY USING ALTER TABLE table SUBQUERY MODIFY (column datatype [DEFAULT expr] A second method to create a table is to [, column datatype]….); apply the as sub query clause to both create ALTER TABLE dept30 the table and rows returned from the MODIFY (enameVARCHAR2(15) ); sub query. Table altered CREATE TABLE table [(Column, column….)] 4.16.5.3 Dropping a Column As sub query; CREATE TABLE dept30 You can drop a column from a table by AS using the ALTER TABLE statement with the SELECT empno, ename, DROP COLUMN clause. sal*12ANNSAL, ALTER TABLE dep30 hiredate DROP COLUMN job; FROM emp Table altered. WHERE deptno=30; Guidelines 4.16.5 THE ALTER TABLE STATEMENT  The column may or may not contain After you create your tables, you may need data to change the table structures because you  Only one column can be dropped at a omitted a column or your column definition time. need to be changed. You can do this by  The table must have at least one column using the ALTER TABLE statement. remaining in it after it is altered You can use the ALTER TABLE statement  Once a column is dropped, it cannot be to: recovered  Add a new column.  Modify an existing column. 4.16.5.4 DROPPING A TABLE  Define a default value for the new column.

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission The DROP TABLE statement removes the The integrity constraints can be defined definition of a table. When you drop a table, using the CONSTRAINT clause. The the database looses all the data in the table CONSTRAINT clause can appear in CREATE and all the indexes associated with it. TABLE and ALTER TABLE commands. This Syntax clause allows the user to define UNIQUE, DROP TABLE table; PRIMARY KEY, NOT NULL, FOREIGN KEY where table is the name of the table and CHECK integrity constraints. The DROP TABLE dept30; CREATE TABLE command is used when the Table dropped constraints are to be defined at the time of table creation. The ALTER TABLE 4.16.5.5 TRUNCATING TABLE command is used when the table already exists and constraints are to be defined. Another DDL statement is the TRUNCATE CREATE TABLE [schema.] TABLE statement, which is used to remove table all rows from a table and to release the (columndatatype [DEFAULT expr] storage space used by that table. When [column_constraint],…….. using the TRUNCATE TABLE statement, [table_constraint] [,….] ); you cannot rollback row removal. 4.16.6.3 Disabling Constraints Syntax TRUNCATE TABLE; You can disable a constraint without dropping it or re-creating it by using the 4.16.6 INCLUDIG CONSTRAINTS ALTER TABLE statement with the DISABLE clause. An integrity constraint can be thought of as Syntax a way to define a business rule for a column ALTER TABLE table or a table. Integrity constraints are defined DISABLE CONSTRAINT constraint with a table and are stored as part of the [CASCADE]; table’s definition in the data dictionary. ALTER TABLE emp DISABLE CONSTRIANT 4.16.6.1 Constraints emp_empno_pk CASCADE;

Constraint Description 4.17 VIEWS NOT NULL Specification that this column may not contain a A view is a logical table based on a table null value based on a table or another view. A view UNIQUE Specifies a column or contains no data of its own but is like a combination of column window through which data from tables whose value must be unique for all rows in table can be viewed or changed. The tables on PRIMARY KEY Uniquely identifies each row which a view is based are called base of the table tables. The view is stored as a SELECT FOREIGGN KEY Establishes and enforces a statement in the data dictionary. foreign key relationship between the column and a 4.17.1 Advantages of Views column of the referenced table.  Views restrict access to the data CHECK Specifies a condition that because the view can display selective must be true. columns from the table.  Views allow users to make simple 4.16.6.2 Defining Constraints queries to retrieve the results from

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission complicated queries. For example, FROM emp a, (SELECT deptno, max(sal) views allow users to query information maxsal from multiple tables without knowing FROM emp how to write a joint statement. GROUP BY deptno) b  Views provide data independence for WHERE a.deptno = b.deptno adhoc users and application programs. AND a.sal

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission Syntax language) and was designed and DELETE [FROM] table implemented at IBM Research, as the [WHERE condition]; interface for an experimental relational DELETE FROM department database system called SYS-TEM R. SQL is WHERE dname= ‘DEVELOPMENT’; now the standard language for commercial relational DBMS. A joint effort by ANSI (the 4.18.4.1 QBE QUERY American National Standards Institute) and ISO (the International Standards QBE is specifically designed for use with a Organization) has led to a standard version visual display terminal QBE has a two- of SQL (ANSI 1986), called SQL-86 or SQL1. dimensional syntax since operations are A revised and much expanded standard specified in tabular form. called SQL 2 (also referred to as SQL-92) The basic idea is that the user formulates has extended SQL with object-oriented and the query by entering an example of a other recent database concepts. possible answer in the appropriate place in SQL is a comprehensive database language; an empty table. For example, consider the it has statements for data definition, query, query 'Get supplier numbers for suppliers and update. Hence, it is both a DDL and a in Paris'. First by pressing a certain DML. In addition, it has facilities for function key on the terminal, the user can defining views on the database, for specifying have a blank "skeleton" table displaced on security and authorization, for defining the screen. Then the user enters S as the integrity constrains and for specifying table-name gets QBE to respond by filling transaction controls. It also has rules for in the column names. The query is embedding SQL statements into a general- expressed as purpose programming language such as C S# SNAME STATUS CITY or PASCAL. P.S7 PARIS The “P” stands for “print”, indicating the 4.18.4.3 SQL commands SQL target of the query. S7 is an “example element” i. e. , an example of a possible provides commands for a variety of tasks answer to the query(indicated by including underlining). PARIS is a “constant element” 1) Querying data QBE automatically eliminates redundant 2) Inserting, updating and deleting rows in duplicates from a query result. If suppress a table each elimination the user can specify the 3) Creating, altering and dropping object key word “ALL”. 4) Controlling access to the database and its objects 4.18.4.2 SQL (STRUCTURED QUERY 5) Guaranteeing database consistency LANGUAGE) 4.18.5 Types of SQL Statements SQL This language consists of commands; each command has an operational part and statements can be divided into three major condition part. Operation is executed categories, through a search in all relations defined in 1) Data Manipulation Language relational database. Required solution (list 2) Data Definition Language, and of data) is returned by the command. The 3) Transaction Control language. data listed in solution satisfies all conditions given in that command. 1) Data Manipulation language: The name SQL is derived from Structured Query Language. Originally, SQL was called These statements consist of queries that SEQUEL (for Structured English QUERY retrieve data from tables in a database and

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission statements that change in the database. The statements under this category are: 2. CHAR (Size) SELECT It specifies a fixed length character string. INSERT Maximum size is 255. Default size is 1 byte. UPDATE If you insert a value that is shorter than the DELETE column length, ORACLE black-pads the LOCK TABLE etc. value to column length. Trying to insert a value too large for column returns an error. 2) Data Definition Language 3. VARCHAR (Size) These statements define the structure of The VARCHAR data type is currently the database. DBL consists of those synonymous with VARCHAR2 data type. statements that create, alter and drop recommends use of database objects and statements that grant VARCHAR2 rather than VARCHAR as and revoke privileges and roles to user of meaning of VARCHAR may change in future the database. The statements under this versions. category are: CREATE 4. NUMBER (P, S) ALTER It is used to store fixed or floating point DROP numbers ranging from 1.0* 10-130 to 9.99* GRANT 10125 P-Precision or total number of digits REVOKE etc. range 1 to 38.

3) Transaction Control Language 5. LONG It stores variable length character strings Transaction control commands manage containing upto 2 gigabytes. LONG columns changes made by data manipulation can be referenced in SQL statements in language commands. These commands are: these places: COMMIT - Select lists ROLLBACK etc. - SET clause of UPDATE statement - VALUES clauses of INSERT 4.18.6 DATA DEFINITION LANGUAGE statement Object Naming Rules 6. DATE Some rules for names of objects and their It is used to date and time information. parts are: Default format in DD-MM-YY. Default  Names must be from 1 to 30 bytes long format can be changed by the NLS-DATE-  Names are not case sensitive FORMAT parameter in int. ora file  A name must begin with an alphabet  Names can only contain alphanumeric 7. ROW ID characters from database Each row in the database has an address of  A name cannot be an Oracle reserved the type block.row.file, where, word. Block: is a hexadecimal string identifying the data block of the data file containing the 4.18.7 DATA Types row length of the string depends on your . 1. VARCHAR2 (Size) Row: A four-digit hexadecimal string It is variable length character string having identifying the row in the data block. The maximum length 'Size' bytes. Maximum first row in the block has the number 0. size is 2000.

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission File: Hexadecimal string identifying the [MODIFYcolumn-namedata_type database file containing the row. Length [column_constraint]]; depends on operating system. First data file Example: has number 1. Alter Table Employee-details add age number; Example: 0000000F.0000.0002 identifies the 4.18.10 VIEWS database file containing the row. Length depends on operating system. First data file A view is a logical table that allows you to has number 1. access data from other tables and views. A view contains no data itself. The tables 4.18.8 Creating Database objects : upon which a view is based are called base Create Command tables. Views are used to: Create statement used to create database —Provide additional level of table security, objects. e. g. Tables, Views, Snonyms etc. by restricting access to a predetermined The syntax of the CREATE TABLE Set of rows/columns of a base table. statement is as follows: —To hide data complexity, for example, a CREATE TABLE Table-name view based on the join of several tables, (Column-name 1 data-type [column actsas a single table. constraint], (Column-name 2 data-type [column Syntax: constraint], CREATE VIEW View-name AS sub query - - - [WITH CHECK OPTION]. - - - Example: Column-name n data-type[column —CREATE VIEW dept 20 constraint], AS SELECT ename, Sal FROM BMP [Table-constraints]); WHERE DEPT NO = 20 The following statement creates an —CREATE VIEW clerk (id-number, person, EMPLOYEE-DETAILS table: department, position) CREATE TABLE Employee-details AS SELECT EMPNO, ENAME, DEPTNO, JOB (Emp_No Number (6) PRIMARY KEY, FROM EMP WHERE JOB = ‘CLERK’ WITH Emp_Name Char (30) NOT NULL CHECK OPTION DEFT Char (20), In this example, the column names in the SALARY Number view have been renamed. Constraint DEPT_CHECK CHECK (DEFT IN (‘ACCOUNT’, WITH CHECK OPTION: ‘PERSONNEL1’, Specific that inserts and updates performed ‘ADMIN’)) through the view must result in rows for ); which the WHERE clause of the view is true. You cannot perform insert, updates or 4.18.9 Altering the Definition of Table: deletes on a view that is based on a join of Alter Command multiple tables. ALTER TABLE command is used to alter the definition of a table in the database. 4.18.11 DATA MANIPULATION The syntax of the command is: LANGUAGE ALTER TABLE name Insert Command ADD column namedata_type [column _INSERT command is used to add rows to a constraint], table.

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission INSERT INTO TABLE-NAME VALUES (data = is equal to value 1, data value 2); I is not equal to The number and sequence of data values <> is not equal to > is greater than should match that of columns in the table. If !> is not greater than the number of data values is less, then < is less than specify the column names into which data !< is not less than is being entered as illustrated. >= is greater than or equal to INSERT INTO TABLE-NAME(column1, <= is less than or equal to column3) 4.19.3 OTHER RELATION PREDICTIONS VALUES (data value 1, data value 3) To insert null values, NULL may be used There are four relational operators that can INSERT INTO EMP VALUES (1001, be used to form relational Predicates. `Sharma` NULL. NULL 3000, NULL); These relational operators are: BETWEEN….. 4.19 QUERIES AND IS NULL Query has two components, a SELECT IN clause and a FORM clause. EXIST The SELECT clause lists names of columns containing the required data and the FROM Example- clause specifies table in which these Consider the following relational database columns are located. The SELECT clause corresponding to the company scheme can also clause specifies operation to be performed on the data and displays the result of these operations. The result of the query is displayed in a table form and is sometimes called the result table. The rows in the result represent the data that meet the conditions. If no data qualifies, zero rows are selected.

4.19.1 NARROWING THE QUERY: THE WHERE CLAUSE

The WHERE clause narrows the scope of the query by focusing on selected rows Example: SELECTNAME, TRAINER FROM GUEST-ROSTER WHERETRAINER = “TODD”, NAME TRAINER SEAN PENCIL TODD DON JACKSON TODD DON JACKSON TODD DIANCA JOGGER TODD

4.19.2 RELATIONAL PREDICATES 4.20 ONE POSSIBLE DATABASE STATE TRAINER=“IODD” is a relational predicate. CORRESPONDING TO THE COMPANY The `=` is a simple relational operator. SCHEME There are nine simple relational operators:

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission Example: Example: Make a query for database given in fig. Show how to make a query on database of retrieve the birthdates and address of the figure given above (Employee database) so employee(s) whose name is `John B. Smith`. that for every project located in 'Stafford' it can list the project number, the controlling department number, and the department manager's last name, address, and birth date. SELECT PNUMER, DNUM, LNAME, ADDRESS, BDATE FROM PROJECT, DEPARTMENT, EMPLOYEE WHERE DNUM = DNUMBER AND MGRSSN = SSN AND PLOCATION = 'Stafford'; which gives the following list.

PNUMBER DNUM LNAME ADDRESS BDATE 10 4 Wallace 291, Berry, 1941-06- Belaire, TX 20 30 4 Wallace 291, Berry, Belaire, TX 1941-06- 20 Example: 333445555 Headquarters Consider database shown in Fig. 1. For each SELECT B/DATE, ADDRESS employee, it is desired to retrieve FROM EMPLOYEE the employee's first and last name and the WHERE FNAME =`John` AND first and last name of his or her immediate MINT = B AND supervisor. Make a query and show the LNAME = `Smith`; results. Which gives the following results Solution. BDATE ADDRESS SELECT E.FNAME, E.LNAME, 1965-01-09 731 S.FNAME, FONDREN, S.L.NAME HOUSTON, TX FROM EMPLOYEE AS E, Example: EMPLOYEE AS S Show a query to retrieve the name and WHERE E.SUPERSSN = S.SSN; address of all employees who work forthe Which gives the following results `Research` department. 333445555 Headquarters SELECT FNAME, LNAME, ADDRESS FROM EMPLOYEDD, E.FNAME E.LNAME S.FNAME S.LNAME DEPARTMENT Jone Smith Franklin Wong WHERE DNAME = `Research` AND Franklin Wong James Borg DNUMBER = DNO. and Alicia Zelaya Jennifer Wallace results of this query are. Jennifer Wallace James Borg NNAME LNAME ADDRESS Ramesh Narayan Franklin Wong Jone Smith 731 Fondren, Houston, TX Joyce English Franklin Wong Franklin Wong 638 Voss, Houston, TX Ahmad Jabbar Jennifer Wallace Ramesh Narayan 975 Fire Oak, Humble, TX Example: Joyce English 5631 Rice, Houston, TX For the database shown in Fig. 1 make a

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission query which selects all EMPLOYEE SSNs SELECT * and show the results also. FROM EMPLOYEE SELECT SSN WHERE DNO = 5; FROM EMPLOYEE; The results of the query are as follows. And the corresponding results are SSN 123456789 333445555 999887777 987654321 666884444 Example: 453453453 For the database of figure given above 987987987 (Employee Database) show the results for 999665555 the following query. Example: SELECT ALL SALARY With respect to database of fig. what will be FROM EMPLOYEE; the result of the following query. The results are as follows SELECT SSN, DNAME SALARY FROM EMPLOYEE, 30000 DEPARTMENT; 40000 The result of this query is 25000 SSN DNAME 43000 123456789 Research 38000 333445555 Research 25000 999887777 Research 25000 987654321 Research 55000 666884444 Research 453453453 Research Example: 987987987 Research Consider database of Figure given above 888665555 Research (Employee Database) and give the results 123456789 Administration corresponding to following query. 333445555 Administration SELECT DISTINCT SALARY 888665555 Administration FROM EMPLOYEE; 999887777 Administration The results are as follows 123456789 Headquarters SALARY 987654321 Administration 30000 666884444 Administration 40000 453453453 Administration 25000 987987987 Administration 43000 999887777 Headquarters 38000 987654321 Headquarters 55000 666884444 Headquarters 453453453 Headquarters Example: 987987987 Headquarters With regard to data base of fig 1, make a 888665555 Headquarters query to retrieve the name of all employees who do not have supervisors. Example: The required query is shown below along With respect to database of Figure given with its results. above (Employee Database) show the SELECT FNAME, LNAME results the following query is made

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission FROM EMPLOYEE the employees. Column order is WHERE SUPERSSN IN NULL; insignificant when storing data; specify And the results are the column order when the data is FNAME LNAME retrieved. James Borg 4. A column containing the department number, which is also a foreign key. A RELATIONAL DATABASE TERMINOLOGY foreign key is a column that defines Table. EMP how tables relate to each other. A foreign key refers to a primary key or a in another table. In the example, DEPTNO uniquely identifies a department in the DEPT table. 5. A field can be found at the intersection of a row and a column. There can be only one value in it. 6. A field may have no value in it. This is called a null value. In the EMP table, only employees who have a role of salesman have a value in the COMM (commission) field. 4.21 TERMINOLOGY USED IN A RELATIONAL DATABASE 4.22 TABLE SAL GRADE.

A relational database can contain one or GRADE LOSAL HISAL TABLE DEPT many tables. A table is the basic storage 1 700 1200 DEPT DNAM LOC NO E structure of an RDBMS. A table holds all the 2 1201 1400 10 ACCO NEWYORK data necessary about something in the real UNTIN world-for example, employees, invoices, or G customers. 3 1401 2000 20 RESER DALLAS The slide shows the contents of the EMP CH 4 2001 3000 30 SALES CHICAGO table or relation. The numbers indicate the 5 3001 9999 40 OPER BOSTON following: ATION 1. A single row or tuple representing all S data required for a particular employee. Fig. Structure and data for three tablet Each row in a table should be EM SAL GRADE identified by a primary key, which allows no duplicate rows. The order of Example: rows is insignificant; specify the row Output for the statements order when the data is retrieved. SQL > SELECT * 2. A column or attribute containing the 2 FROM DPT; employee number, which is also the DEPT NO DNAME LOC primary key. The employee number 10 ACCOUNTING NEWYORK identifies a unique employee in the EMP 20 RESERCH DALLAS table. A primary key must contain a 30 SALES CHICAGO 40 OPERATIONS BOSTON value. 3. A column that is not a key value. A Example: column represents one kind of data in a Output of the statements, table; in the example, the job title of all

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission SQL >SELECT ename, hiredale, sal Output corresponding to 2 >FROM emp; SQL> SELECT ename, "Name", ENAME HIREDATE SAL 2 Sal* 12 "ANNUAL SALARY" KING 17-NOV-81 5000 3 FROM emp; BLACK 01-MAY-81 2850 NAME ANNUAL SALARY CLARK 09-JUN-81 2450 JONES 02-APR-81 2975 Example: MARTIN 28-SEP-81 1250 Output for ALLEN 20-FEB-81 1600 SQL > SELECT ename, / / job 14 rows selected AS "Employees" 2 FROM emp; Example: EMPLOYEES Show the output corresponding to KINGPRESIDENT following BLAKEMANAGER CLARK SQL> SELECT ename, sal, salt 300, MANAGER JONES MANAGER 12* (sal + 1000) MARTIN SALESMAN ENAME SAL SAL+300 12*(SAL+100) ALLENSALESMAN KING 5000 5300 61200 …. BLACK 2850 3150 35400 13 Rows selected CLARK 2450 2750 30600 JONES 2975 3275 36900 Example: MARTIN 1250 1550 16200 ALLEN 1600 1900 20400 Show output for 14 rows selected SQL> SELECT ename, / /’:’//'/’// "Month Salary" = / / Sal Monthly Example: 2 FROM emp; Output for MONTHLY SQL> SELECT ename, job, sal, KING: | Month Salary = 5000 comm. BLAKE: | Month Salary = 2850 FROM emp; CLARK: | Month Salary = 2450 ENAME JOB SAL COMM JONES | Month Salary = 2975 KING PRESIDENT 5000 …. BLAKE MANNER 2850 14 rows selected ………… TURNER SALESMAN 1500 0 Example: ……………. O/p for ……….. SQL > SELECT depto no 14 rows selected 2 FROM emp; Example: DEPT NO. Output for the 10 SQL> SELECT ename, 12* sal + 30 comm. 10 2 FROM emp 20 3 WHERE ename = `KING`; 14 rows selected ENAME 12 * SAL + COMM Example: KING O/p for This is because the comm column in the SQL> SELECTDISTINCTdepot no arithmetic expression is null, the result is 2 FROM emp; null. DEPT NO. Example: 10

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission 30 10 There are only three unique department numbers in the table. Example: O/p for SQL> SELECT DISTINCT depot no, Job 2 FROM emp; DEPT NO. JOB 10 CLERK 10 MANAGER 10 PRESIDENT 20 ANALYST ………. 9 rows selected

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission 5 FILE STRUCTURE

5.1 RECORDS AND RECORD TYPES char ssn [9]; int salary; Data is usually stored in the form of int job code; records. Each record consists of a char department [2,0] collection of related data values of items, }; where each value is formed of one or more In recent database applications, it is bytes and corresponds to a particular field required for storing data items that consist of the record. Records usually describe of large unstructured objects, which entities and their attributes. For example, represent images, digitized video or audio an EMPLOYEE record represents an streams, or free text. employee entity, and each field value in the These are referred to as BLOBs (Binary record specifies some attribute of that Large Objects). A BLOB data item is employee, such as NAME,BIRTHDATE, typically stored separately from its record SALARY, or SUPERVISOR. A collection of in a pool of disk blocks, and a pointer to the field names and their corresponding data BLOB included in the record. types constitutes a record type or record format definition. 5.1.2 FILES, FIXED –LENGTH RECORDS, A data type, associated with each field, AND VARIABLE-LENGTH RECORDS specifies the type of values a field can take. The data type of a field is usually one of the A file is a sequence of records. In many standard data types used in programming. cases, all records in a file are of the same These include numeric (integer, long record type. If every record in the file has integer, or floating point), String of exactly the same size (in bytes), the file is characters (fixed-length or varying), said to be made up to of fixed-length Boolean (having 0 and 1 or TRUE and records. If different records in the file have FALSE values only), and sometimes different sizes, the file is said to be made up specially coded date and time data types, of variable Length records. The fixed-length EMPLOYEE records in 5.1.1 The number of bytes required for Figure have a record size of 71 bites. Every each data type is fixed for a given record has the same fields, and field lengths computer System. are fixed, so the system can identify the starting byte position of each field relative Integer may require 4 bytes, a long integer to the starting position of the record 8 bytes, a real number 4 bytes, a Boolean 1 byte, a data 10 bytes (assuming a format of YYYY-MM-DD), and a fixed-length string of k characters k bytes. Variable-length strings may require as many bytes as there are characters in each field value. For example, an EMPLOYEE record type may be defined-using the C programming language notation-as the following structure: struct employee { char name [3];

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission 5.1.3 THREE FIELD RECORD STORAGE There are several standard techniques for FORMATS allocating the block of a file on disk. In contiguous allocation the file blocks are For variable-length fields; each record has allocated to consecutive disk blocks. This a value for each field, but we do not know makes reading the whole file very fast the exact length of some field values. To using double buffering, but it makes determine the bytes within a particular expanding the file difficult. In linked- record that represents each field, we can allocation each file block contains a use special separator characters (such as? pointer to the next file block. This makes it Or % $) - which do not appear of the field easy to expand the file but makes it slow to value-terminate variable-length fields or read the whole file. A combination of the we can store the length in bytes of the field two allocates clusters of consecutive disk in the record, preceding the field value. blocks, and the clusters are linked. Clusters are sometimes called file segments or 5.1.4 RECORD BLOCKING AND SPANNED extents. Another possibility to use VERSUS UNSPANNED RECORDS indexed allocation, where one or more The records of a file must be allocated to index blocks contain pointers to the actual disk blocks because a block is the unit of file blocks. It is also common to use data transfer between disk and memory. combinations of these techniques. When the block size is larger than the record size, each block will contain 5.1.4.2 ORGANIZATION AND ACCESS numerous records. Although some files METHOD may have unusually large records that cannot fit in one block. Suppose that the The difference between the terms file block size is B bytes. For a file of fixed- organization and access method is: A file length records or size R bytes, with B  ,R organization refers to the organization of we can fitbfr = floor[B/R] records per the data of file into records, blocks, and block, where the floor(x) (floor function) access structures; this includes the way rounds down the numbers x to an integer. records and blocks are placed on the The value bfr is called the blocking factor storage medium and interlinked. An access of the file. In general, R may not divide B method, on the other hand, provides a exactly we leave some unused space in group of operations-such as those listed each block equal to B- (bfr * R) bytes. earlier-that can be applied to a file. In To utilize this unused space, we can store general, it is possible to apply several part of a record on one block and the rest access methods to a file organization. Some on another. A pointer at the end of the first access methods, though, can be applied block points to the block containing the only to files organized in certain ways. For remainder of the record in case it is not the example, we cannot apply an indexed next consecutive block on disk. This access method to a file without an index. organization is called spanned, because records can span more than one block. 5.1.4.3 DIFFERENT FILE ORGANIZATION Whenever a record is larger than a block, we must use a spanned organization. If Three primary file organizations are there records are not allowed to cross block unordered, ordered and hashed. Unordered boundaries, the organization is called un- files require a linear search to locate spanned. records, but record insertion is very simple. 5.1.4.1 ALLOCATING FILE BLOCKS ON 5.1.5 Files of Unordered Records (Heap DISK Files)

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission In this simplest and most basic type of After such reorganization, the blocks are organization, records are placed in the file filled to capacity once more. Another in order in which they are inserted, so new possibility is to use the space of deleted records are inserted at the end of the file. records when inserting new records, Such an organization is called a heap or although this requires extra bookkeeping pire file. to keep track of empty locations. This organization is often used with additional access paths, such as the 5.1.6 Files of Ordered Records (Sorted secondary indexes. It is also used to collect Files) and store data records for future use. Inserting a new record is very efficient: the We can physically order the records of a last disk block of the file is copied into a file on disk based on the value of one of buffer; the new record is added; and the their fields called the ordering field. This block is then rewritten back to disk. The leads to an ordered or sequential file. If the address of the last file lock is kept in the file ordering field is also a key field of the file-a header. However, searching for a record field guaranteed to have a unique value in using any search condition involves a linear each record-then the field is called the search through the file block by block-an ordering key for the file. expensive procedure. If only one record satisfies the search condition, then, on the 5.1.7 Ordered records have advantages average, a program will read into memory over unordered files and search half the file block before it finds the record. For a file of blocks, this requires 1) First, reading the records in order of the searching (b/2) blocks, on average. If no ordering key values become externally records on several records satisfy the efficient because no sorting is required. search condition, the program must read 2) Finding the next record from the and search all blocks in the file. current one in order of the ordering key To delete a record, a program must first usually requires no additional block find its block, copy the block into a buffer, accesses, because the next record is in then delete the record from the buffer, and the same block as the current one finally rewrite the block back to the disk. (unless the current record is the last This leaves unused space in the disk block. one in the block). Deleting a large number of records in this 3) Using a search condition based on the way, results in wasted storage space. value of an ordering key field results in Another technique used for record deletion faster access when the binary search is to have an extra byte or bit, called a technique is used, this constitutes an deletion marker, stored with each record. improvement over linear searches, A record is deleted by setting the deletion although it is not often used for disk marker to a certain value. A different value files. of the marker indicates a valid (not A binary search for disk files can be done deleted) record. Search programs consider on the block rather than on the records. only valid records in a block when Suppose that the file has b blocks conducting their search. Both of these numbered 1, 2,……, b; the records are deletion techniques require periodic ordered by ascending value of their reorganization of the file to reclaim the ordering key field; and we are searching for unused space of deleted records. During a record whose ordering field value is K. reorganization, the file blocks are accessed Inserting and deleting records are consecutively, the records are packed by expensive operations for an ordered file removing deleted records. because the records must remain

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission physically ordered. To insert a record, we an address that already contains a different must find its correct position in the file, record. In this situation, we must insert the based on its ordering field value, and then new record in some other position, since its make space in the file to insect the record hash address is occupied. The process of in that position. For a large file can be very finding another position is called collision time-consuming because, on the average, resolution. half the file blocks must be read and rewritten after records are moved among ii)External Hashing for Disk Files them. For record deletion, the problem is less severe if deletion makers and periodic Hashing for disk files is called external reorganization are used. hashing. To suit the characteristics of disk storage, the target address space is made of 5.1.8 Hashing Techniques buckets, each of which holds multiple Another type of primary file organization is records. A bucket is either one disk block or based on hashing, which provides very fast a cluster of continuous blocks. The hashing access to records on certain search function maps a key into a relative bucket conditions. This organization is usually number, rather than assign an absolute called a hash file. The search condition block address to the bucket. A table must be an equality condition on a single maintained in the file header converts the field, called the hash field of the file. In bucket number into the corresponding disk most cases, the hash field is also a key field block address. of the file, in which case it is called the hash The collision problem is less severe with key. The idea behind hashing is to provide a buckets, because as many records as will fit function h, called a hash function or in a bucket can hash to the same bucket randomizing function, that is applied to the without causing problems. However, we hash field value of a record and yields the must make provisions for the case, where a address of the disk block in which the bucket is filled to capacity and a new record is stored, a search for the within the record being inserted hashes to that block can be carried out in a main memory bucket. We can use a variation of chaining buffer. For most records, we need only a in which & pointer is maintained in each single-block access to retrieve that record. bucket to a linked list of overflow records for the bucket. The pointers in the linked i) Internal Hashing list should be record pointers, which include both a block address and a relative For internal files, hashing is typically record position within the block. implemented as a hash table through the Hashing provides the fastest possible use of an array records. Suppose that the access for retrieving an arbitrary record array index range is from 0 to M - 1 then we given the value of its hash field. have M slots whose addresses correspond to the array indexes. We choose a hash 5.1.9 OTHER PRIMARY FILE function that transforms the hash field ORGANIZATIONS value into an integer between 0 and M - 1. One common hash function is the h(K) = K Files of Mixed Records mod M function, which returns the The file organizations so far assume that all remainder of an integer hash field value K records of a particular file are of the same offer division by M, this value is then used record type. The records could be of for record address. EMPLOYEES, PROJECTS, STUDENTS, or A collision occurs when the hash field value DEPARTMENTS, but each file contains of a record that is being inserted hashes to records of only one type.

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission 5.2 B-TREES & OTHER DATA STRUCTURES i) For any two groups, all the stored record occurrences in one precede all Other data structures can be used for those in the other (with respect to the primary file organizations. For example, if sequencing being imposed on the file). both the record size and the number of ii) Within any one group, the file sequence records in a file are small, some DMBS’s is represented by physical contiguity. offer the option of a B-tree data structure The index contains one entry per / group, as the primary files organization. Any data giving the highest value of the indexed field structure that can be adapted to the occurring in the group and a pointer to the characteristics of disk devices can be used start of the group. The term “non-dense” as a primary file organization for record refers to the fact that the index does not placement on disk. contain an entry for every stored record Ordered files shorten the time required to occurrence in the indexed file. read records in order of the ordering field. The time required to search for an 2. Multilevel Indexing arbitrary record, given the value of its ordering key field, is also reduced if a A multilevel (tree structure) index can binary search is used. However, maintaining contain any number of levels, each of which the records in order makes insertion very acts as a non- dense index to the level expensive; thus the technique of using an below. The top level, contain a single entry. unordered overflow file to reduce the cost B-trees: B-Tree is a particular form of of record insertion was discussed. Overflow multilevel for tree structure index. B-tree records are merged with the master file actually denotes the index set. The nodes of periodically during file reorganization. a B-tree do not normally contain the same Hashing provides very fast access to an number of value entries. They normally do arbitrary record of a file, given the value of contain a certain amount of free space. In its hash key. The most suitable method for general, a B-tree of order n has at least n external hashing is the bucket technique, but not more than 2n value entries at any with one or more contiguous blocks given node (and, if it has K value entries, corresponding to each bucket. Collisions then it also has K + n pointers). causing bucket over-flow are handled by Advantage: The B-tree insertion/deletion chaining. Access on any non hash field is algorithm guarantees that the tree will slow, and so is ordered access of the remain balanced. records on any field. 3. Indexing on Field Combinations

5.2.1 INDEXING TECHNIQUES It is possible to construct an index on the Indexes are required to represent the basis of the values of two or more fields in sequence of stored record occurrences combination. In general, an index on the within their stored file. The, various combination of n fields F1, F2, ……Fn(in that indexing techniques used are: order) will also serve. As an index on F1, as an index on the combination F1 F2 (or F2 F1), as an index on the combination F1 F2 F3 1. Non-dense indexing (in any order), and so on. 4. Selectivity in the Index The file being indexed is divided into groups, with several record occurrences in It is not necessary to provide access via the each group, such that’s the following index to every record occurrence in the conditions hold. indexed file. In some situations, it may be useful to have index entries for selected7

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission values only of the indexed field. For subtree pointed at by Pi (the ith subtree, example, in an employee file with 95% see given Figure below, we have: employees having status exempt and 5% Ki-1< X < Ki for 1 < i < q; X < Ki for i = 1; non-exempt, it would be very useful to have and Ki-1< X for i = q. an index pointing to all non-exempt 4. Each node has at most p tree pointers. employees. 5. Each node, except the root and leaf nodes, has at least [(p/2)] tree pointers. 5. Symbolic Pointer Representation: The root node has at least two three pointers unless it is the only node in the SRA-valued pointers can be replaced by the tree. corresponding primary key values. This 6. A node with q tree pointers, q ≤ p, has q value can then be used to locate the - 1 search key field values (and hence corresponding record. An index using has q -1 data pointers). symbolic keys will clearly not need to be 7. All leaf nodes are at the same level. Leaf updated just because the indexed file has nodes have the same structure as been reorganized. However, access via that internal nodes except that all of their index will be slower than access via an tree pointers Pi are null index that uses direct pointers.

CITY FILE SUPPLIER FILE

5.2.2 B-TREES 5.2.3 Fig. B-tree structures.

A B-tree of order p, when used as an Figure illustrates a B-tree of order p=3. All access structure on a key field to search for search values K in the B-tree are unique records in a data file, can be defined as because we assumed that the tree is used follows: as an access structure on a key field. If we 1. Each internal node in the B-tree which use a B-tree on a non key field, we must is given in below figure is of the form change the definition of the file pointers Pri , P2, < K2, Pr2>,…, Pq> the pointers to the file records. where q  p. Each Pi.is a tree pointer-a B-tree starts with a single root node (which pointer to another node in the B-tree. is also a leaf node) at level 0(zero). Once Each Pri is a data pointer-a pointer to the root node is full with p-1 search key the record whose search key field value values and we attempt to insert another is equal to K. (or to the data file block entry in tree, the root node splits into two containing that record). nodes at level 1. Only the middle value is 2. Within each node, K1< K2< …< Kq-1. kept in the root node, and the rest of the 3. For all search key field values X in the

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission values are split evenly between the other data pointer. In a B+-tree, data pointers are two nodes. When a no root node is full and stored only at the leaf nodes of the tree; a new entry is moved to the parent node is hence, the structure of leaf nodes differs split into two nodes at the same level, and from the structure of internal nodes. The the middle entry is moved to the parent leaf nodes have an entry for every value of node along with two pointers to the new the search field, along with a data pointer split nodes. If the parent node is full, it is to the record (or to the block that contains also split. Splitting can propagate all the this record) if the search field is a key field. way to the root node, creating a new level if For a non key search field, the pointer the root is split. points to a block containing pointers to the If deletion of a value causes a node to be data file records, creating an extra level of less than half full, it is combined with its indirection. The leaf nodes of the B+-tree neighbouring nodes, and this can also are usually linked together to provide propagate all the way to the root. Hence, ordered access on the search field to the deletion can reduce the number of tree record. These leaf nodes are similar to the levels. It has been shown by analysis and first (base) level of an index. Internal nodes simulation that, after numerous random of the B+-tree correspond to the other insertions and deletions on a B-tree, the levels of a multilevel index. Some search nodes are approximately 69 percent full field values from the leaf nodes are when the number of values in the tree repeated in the internal nodes of the B+- stabilizes. This is also true of B*-trees. If tree to guide the search. The structure of this happens, node splitting and combining the internal nodes of a B'-tree of order p will occur only rarely, so insertion and Figure is as follows: deletion becomes quite efficient. If the 1. Each internal node is of the form where q  p and expand without a problem-although each Pi, is a tree pointer. splitting of nodes may occur, so some 2. Within each internal node, K1,< K2,< … insertion will take more time. entries. This works well for files 4. Each internal node has at most p tree with a relatively small number of records, pointers. and a small record size. Otherwise, the fan- 5. Each internal node, except the root, has out and the number of levels become too at least [(p/2)] tree pointers. The root great to permit efficient access. In node has at least two tree pointers if it summary, B-trees provide a multilevel is an internal node. access structure that is a balanced tree 6. An internal node with q pointers, q  p, structure in which each node is at least half has q - 1 search field values. full. Each node in a B-tree of order p can have at most p - 1 search values. 5.2.4 B+-TREES Most implementations of a dynamic multilevel index use a variation of the B- tree data structure called a B+-tree. In a B- tree, every value of the search field appears once at some level in the tree, along with a (a) Internal node of a B'-tree with q-1 search value

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission nodes which we define as being the maximum number of data pointers in a leaf node.

5.2.5 Variations of B-Trees and B+-Trees In some cases, constraint 5 on the B-tree The structure of the leaf nodes of a B+- tree (or B+-tree), which requires node to be at of order p (Figure) is as follows: least half full, can be changed to require 1. Each leaf is of the from <, ,……….,, Pnext> this case the B-tree has been called a B*- where q  P, each Pri each is a data tree. In general, some systems allow the pointer, and Pnext points to the next leaf user to choose a fill factor between 0.5 and node of the B+-tree. 1.0, where the latter means that the B-tree 2. Within each leaf node, K1< K2<……..< Kq- (index) nodes are to be completely full. It is 1, q p. also possible to specify two fill factors for a 3. Each Pri is a data pointer that points to B+-tree: one for the leaf level and one for the record whose search field value is Ki the internal nodes of the tree. When the or to a file block containing the record index is first constructed, each node is filled (or to a block of record pointers that up to approximately the fill factors point to records whose search field value specified. Recently, investigators have is Ki if the search field is not a key). suggested relaxing the requirement that a 4. Each leaf node has at least [(p/2)] node be half full, and instead allow a node values. to become completely empty before 5. All leaf nodes are at the same level. merging, to simplify the deletion algorithm. Simulation studies show that this does not The pointers in internal nodes are tree waste too much additional space under pointers to blocks that are tree nodes, randomly distributed insertions and whereas the pointers in leaf nodes are data deletions. pointer to the data file records or blocks- except for the Pnext pointers which is a tree 5.3 DBMS leaf nodes as a linked list using Pnext pointers. This provides ordered access to 5.3.1 What is data model? the data records on the indexing field. A A collection of tools for describing data Pprevious pointer can also be included. For a Data relationships B+-tree on a non key field, so the Pr Data semantics pointers are block pointers to block that Data constrains contain a set of record pointers to the actual records in the data file. 5.3.2 System model tools: Because entries in the interval nodes of a B+-tree include search values and tree Data flow diagram (DFD) pointers without any data pointers, more Hierarchical input process and output entries can be packed into an internal node (HIPO) of a B+ -tree than for a similar B-tree. The State transition diagrams (STD) can lead to fewer B+-tree levels, improving Entity relationship (ER) diagrams search time. Because the structures for 5.3.3 Entity-Relationship Model (ER + internal and for leaf nodes of a B -tree are Model) different, the order P can be different. We will use p to denote the order for internal A data model in which information stored nodes and Pleaf to denote the order for leaf in the database is viewed as sets of entities

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission and sets of relationships among entities contained entities. The value of the and it is diagram-based representation of attribute can be different for each entity domain knowledge, properties etc….., but it in the set. is more intuitive and less mechanical 5.3.7.1 Domain of Attribute 5.3.4 Components of ER model a)Entity A set of possible values for an attribute b)Relationship (thetype of attribute) c) Attributes Example: 5.3.5 Entity The domain of student name might be strings of some fixed length. The domain of Something that exists and can be roll number might be 10 digit positive distinguished from other entities. integers or alphanumeric. Examples: Student entities with unique roll numbers Account entities with unique 5.3.8 Relationship Degrees account Numbers The number of entity types associated with 5.3.5.1 Entity set that relationship. A set of entities of the same type  Example: All the student entities in a college  Entity sets need not be disjoint. Example: a person entity could be in both the customer and employee sets.

5.3.5.2 Types of entities Entities with physical existence 5.3.9 Types of relationships

Example: Student, customer, Book etc Entities with Conceptual existence

Example: Sale, University course etc

5.3.6 Relationship Set

A set of relationships of the same type 5.3.7 Attribute 5.3.10 Multiplicity

A characteristic of an entity Multiplicity constrains the way that entities  Example: A student entity might have are related- It is a representation of the attributes such as: Roll number, name, policies (or business rules) established by age, address etc. the user or enterprise. Multiplicity actually  As all entities in an entity set have the consists of two separate constraints same attributes, entity sets also have attributes –the attributes of the 5.3.11 Cardinality

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission Address attribute composed of street, city Which describes the maximum number of and postcode attributes possible relationship occurrences for an entity participating in a given relationship type i.e. how many relationship instances is an entity permitted to be linked to.

5.3.12 Participation

Which determines whether all or only some entity occurrences participate in a relationship i.e. how is an entity linked to the relationship

5.3.12.1 Total participation (indicated by double line): Single-valued: Department No attribute of Department Every entity set participates in at least one Multi-valued: relationship in the relationship set Telephone No attribute of faculty Stored: 5.3.12.2 Partial participation Date of birth attribute of student Derived: Some entities may not participate in any Age attribute is derived from date of birth relationship in the relationship set 5.3.13 Weak and a strong entity set Note: Cardinality limits can also express participation constraints A strong entity set has a primary key. All tuples in the set are distinguishable by that key. A weak entity set has no primary key unless attributes of the strong entity set on which it depends are included. Tuples in a weak entity set are partitioned according to their relationship with tuples in a strong entity set. Tuples within each are distinguishable by a discriminator, which is a set of attributes. An entity set that does not have a primary key is referred to as a weak entity set. The existence of a weak relate to the identifying entity set via a total, one-to-many 5.3.12.3 Types or attributes relationship set from the identifying to the weak entity set. Identifying relationship 1. Simple and composite depicted using a double diamond. 2. Single-valued and multi-valued The discriminator (or partial key) of a 3. Stored and derived attributes weak entity set is the set of attributes that distinguishes among all the entities of a Simple: weak entity set. The primary key of a weak Position or salary attribute of faculty entity set is formed by the primary key of Composite: the strong entity set on which the weak

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission entity set is existence dependent, plus the year) and section-number (if there is more weak entity set’s discriminator than one section). If we model course- offering as a strong entity we would model course-number as an attribute. Then the relationship with course would be implicit in the course–number attribute

5.4 EXISTENCE DEPENDENCIES

If the existence of entity x depends on the We depict a weak entity set by double existence of entity y, then x is said to be rectangles. We underline the discriminator existence dependent on y, y is a dominant of a weak entity set with a dashed line. entity, x is a subordinate entity. If y entity is Payment-number-discriminator of the deleted, then all its associated x entities payment entity set Primary key for must be deleted. payment – (loan-number, payment- number) 5.4.1 ER diagram symbols Note: The primary key of the strong entity set is not explicitly stored with the weak entity set, since it is implicit in the identifying relationship. If loan-number were explicitly stored, payment could be made a strong entity, but then the relationship between payment and loan would be duplicated by an implicit relationship defined by the attribute loan- number common to payment and loan.

5.3.14 Reasons to have weak entities

We want to avoid the data duplication and consequent possible inconsistencies caused by duplicating the key of the strong entity. Weak entities reflect the logical structure of an entity being dependent on another entity.

5.3.14.1 Weak:

Entities can be deleted automatically when their strong entity is deleted. Weak entities can be stored physically with their strong entities

Examples In a university, a course is a strong entity and a course-offering can be modelled as a weak entity. The discriminator of course- offering would be semester (including

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission 5.4.2 Keys

Super key of an entity set is a set of one or more attributes whose values uniquely determine each entity and a key is a minimal super key: no subset of columns can determine entity. A candidate key of an entity set is a b) Manufactures have tie-ups with minimal super key Student roll no is distributors to distribute products. Each candidate key of student table, Book Accno tie-up has specified for it the set of is candidate key of Book table. Although products which are to be distributed. several candidate keys may exist, one of the candidate keys is selected to be the primary key. The combination of primary key of the participating entity sets forms a super key of a relationship set. (customer-id, account) is the super key of depositor. NOTE: This means a pair of entity sets can have at most one relationship in a particular relationship set. E.g. if we wish to track all access-dates to each account by each customer, we cannot assume a relationship for each access. We can use a multi valued attribute though must consider the mapping cardinality of the relationship set when deciding, what are the candidate 5.4.4 Utility of E-R Model keys Need to consider semantics of relationship set in selecting the primary  It maps well to the relational model. key in case of more than one candidate key. The constructs used in the ER model can easily be transformed into 5.4.3 Aggregation relational tables.  It is simple and easy to understand with Aggregation is an abstraction through a minimum of training. Therefore, the which relationships are treated as higher- model can be used by database designer level entities. Thus the relationship to communicate the design to the end between entities A and B is treated as if it user. were an entity C. Some examples of this are:  In addition, the model can be used as a a) Employees work for projects. An design plan by the database developer employee working for a particular to implement a data model in specific project uses various machinery. database management software.

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission 5.4.5 E-R Design Decisions

The use of an attribute or entity set to e) Represent all the ER diagrams represent object. Whether a real-world described in (a), (b), (c), and (d) as a concept is best expressed by an entity set single ER diagram. or a relationship set. The use of a ternary relationship versus a pair of binary relationships. The use of a strong of weak entity set. The use of specialization/ generalization – contributes to modularity in the design. The use of aggregation – can treat the aggregate entity set as a single unit without concern for the details of its internal structure. 2. You are required to create a conceptual data model of the data requirements for 5.4.6 Tools to create E-R Diagrams a company that specializes in IT training. The Company as 30 instructors Several Computer Assisted Software and can handle up to 100 trainees per Engineering (CASE) Tools exist to help training session. The Company offers create E-R Diagrams and the resulting five advanced technology courses, each physical database elements. Products of which is taught by a teaching team of include: two or more instructors. Each instructor -IEW is assigned to a maximum of two -IEF teaching teams or may be assigned to -DEFT do research. Each trainee undertakes -ER-WIN one advanced technology course per -Visio training session. a) Identify the main entity types for the Exercises company 1. Create an ER diagram for each of the b) Identify the main relationship types and following descriptions: specify the multiplicity for each a) Each company operates four relationship. State any assumptions you departments, & each department make about the data. belongs to one company c) Using your answers for (a) and (b), draw a single ER diagram to represent the data requirements for the company. b) Each department in part (a) employs one or more employees, and each Answer: employee works for one department.

c) Each of the employees in part (b) may or may not have one or more dependants, & each dependant belongs to one employee. 3. Consider a database used to record the d) Each employee in part (c) may or may marks that students get in different not have an employment history. exams of different course offerings.

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission Construct an E-R diagram that models exams as entities, Answer:

4. A university registrar’s office maintains data about the following entities: (a) Student (student-id, name, program) courses including number, title, credits, Course (courseno, title, syllabus, credits) syllabus, and prerequisites: (b) course Course-Offering offerings, including course number, (courseno,secho,year,semester,time, room) year semester, section, number, Instructor (instructor-id, name, dept, title) instructor(s), timings, and classroom; Enrolls(student- (c) students, including student-id, id,courseno,secno,semester,year, grade) name, and program; and (d) instructors, Teaches (courseno,secno,semester,year, including identification number, name, instructor-id) department, and title. Further, the Requires (main course,prerequisite) enrollment of students in courses and 5. Construct an E-R diagram for a car- grades awarded to students in each insurance company whose customers course they are enrolled for must be own one or more cars each. Each car appropriately modelled. Construct an E- has associated with it zero to any R diagram for the registrar’s office. number of recorded accidents. Convert Document all assumptions that you ER diagram into equivalent Relational make about the mapping constraints. tables. Convert ER diagram into equivalent Relational tables Answer :

Answer: In the answer given here, the main entity sets are student, course, course-offering, and instructor. The entity set course- offering is a weak entity set dependent on course. The assumptions made are: a) A class meets only at one particular place and time. This E-R diagram cannot model a class meeting at different places at different times. b) There is no guarantee that the database Car insurance Tables does not have two classes meeting at Person (driver-id, name, address) the same place and time. Person (license, year, model) Accident (report-number, data, location) 5.4.7 University registrar’s tables: Participated (driver-id,license,report- number, damage-amount)

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission 6. Construct an E-R diagram for a hospital with a set of patients and a set of medical doctors. Associate with each patient a log of the various tests and examinations conducted. Convert ER diagram into equivalent Relational tables.

Answer:

tables: Patients (patient-id, name, insurance , date-admitted, date-check-out) Doctors (doctor-id, name, specialization) Test (testid, test name, date, time, and result) Doctor-patient (patient-id,doctor-id) Test-log (testid,patient-id) Performed-by (testid,doctor-id)

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission GATE QUESTIONS Topics Page No

1. ER-MODEL

2. DATABASE DESIGN: FUNCTIONAL DEPENDENCIES & 52 NORMALIZATION

3. STRUCTURED QUERY LANGUAGE (SQL) 56

4. RELATIONAL MODEL: RELATIONAL ALGEBRA AND 67 TUPLE CALCULUS

5. TRANSACTIONS & CONCURRENCY CONTROL 83

6. FILE STRUCTURES 91

103

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission 1 ER-MODEL

Q.1 It is desired to design an object- attribute. The attributes of E2 are oriented employee record system A21, A22 and A23 is the key for a company_ each employee has a attribute and A23 is a multi-valied name, unique Id and salary. attribute. Relation R does not have Employees belong to different any attribute. A relational database categories and their salary is containing minimum number of determined by their category. The table with each table satisfying the functions get Name, getld and requirements of the third normal compute salary are required. Given form (3NF) is designed from the the class hierarchy below, possible above ERD. The number of table in locations for these functions are the database is 1. getld is implemented in the a) 2 b) 3 super class c) 5 d) 4 2. getld is implemented in the [GATE-2004] subclass 3. getld Name is an abstract Q.3 Consider the entities ‘hotel room’, function in the super class and ‘person’ with a many to many 4. getld Name is implemented in relationship ‘lodging’ as shown the super class below: 5. getld Name is implemented in the subclass 6. getld salary is an abstract If we wish to store information function inthe super class about the rent payment to be made 7. getld salary is implemented in by person (s) occupying different the supercla.ss hotel rooms, then this information 8. getld salary is implemented in should appear as an attribute of the subclass a) Person b) Hotel Room c) Lodging d) None of these [GATE – 2005]

Q.4 Let E1 and E2 be two entities in an E/R diagram with simple single valued attributes. R1 and R2 are two Choose the best design. relationships between El and E2, a) 1, 4, 6, 7 b) 1, 4, 7 where R1 is one-to-many and R2 is c)1, 3, 5, 6, 8 d) 2,5,8 many-to-many. R1, and R2 do not [GATE – 2004] have any attributes of their own. What is the minimum number of Q.2 Consider the following entity tables required to represent this relationship diagram (ERD), where situation in the relational model? two entities E1 and E2 have a a) 2 b) 3 relation R of cardinality 1: m c) 4 d) 5 [GATE – 2005] The attributes of E1 are A11, A12 Q.5 The following table has two attributes and A13 where A11 is the key A and C where A is the primary key

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission and C is the foreign key referencing c) In a row of a relational table A with on-delete cascade. anattribute can have more than A C one value 2 4 d) In a row of a relational table, an 3 4 attribute can have exactly one 4 3 5 2 value or a null value 7 2 [GATE – 2012]

9 5 Consider an Entity-Relationship(ER) 6 4 Q.9 The set of all tuples that must be model in which entity sets E1and E2 additionally deleted to preserve are connected by an m : n when the tuple relationship R12, E1 and E3 are (2, 4) is deleted is: connected by a 1 : n (1 on the side of a) (3, 4) and (6, 4) E1 and n on the side of E3) b) (5, 2) and (7, 2) relationship R13. c) (5, 2) (7, 2) and (9,5)  E1 has two single-valued d) 1 attributes a11 and a12 of which a11 is the key attribute. [GATE – 2005]  E2 has two single-valued Statements for Linked Answer Q.6 & Q.7 attributes a21 and a22 of which Consider the following ER diagram. a21 is the key attribute.  E3 has two single-valued attributes a31 and a32 of which a31 is the key attribute.  The relationships do not have any attributes. If a relational model is derived from Q.6 The minimum number of tables the above ER model, then the needed to represent M, N, P, R1,and R2 minimum number of relations that a) 2 b) 3 would be generated if all the c) 4 d) 5 relations are in 3NF is ______. [GATE – 2008] [GATE 2015]

Q.7 Which of the following is a correct Q.10 An ER model of a database consists attribute set for one of the tables for of entity types A and B. These are the correct answer to the above connected by a relationship R which question? does not have its own attribute. a) {M1, M2, M3, P1} b) {M1, P1, N1, Under which one of the following N2} conditions, can the relational table c) {M1, P1, N1} d) {M1, P1} for R be merged with that of A? [GATE – 2008] a) Relationship R is one – to- many Q.8 Given the basic ER and relational and the participation of A in R is models, which of the following is total incorrect? b) Relationship R is one- to- many a) An attribute of an entity can and the participation of A in R is have more than one value partial b) An attribute of an entity can be c) Relationship R is many- to- one composite and the participation of A in R is total

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission d) relationship R is many – to – one and the participation of A in R is partial [GATE 2017] Q.11 In an Entity-Relationship (ER) model, suppose R is a many-to-one relationship from entity set E1 to entity set E2. Assume that E1 and E2 participate totally in R and that the cardinality of E1 is greater than the cardinality of E2. Which one of the following is true about R? a) Every entity in E1 is associated with exactly one entity in E2. b) Some entity in E1 is associated with more than one entity in E2. c) Every entity in E2 is associated with exactly one entity in E1. d) Every entity in E2 is associated with at most one entity in E1. [GATE-2018]

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission ANSWER KEY: 1 2 3 4 5 6 7 8 9 10 11 (a) (b) (c) (b) (c) (b) (a) (c) 4 (c) (a)

EXPLANATIONS

Q.1 (a) Otherwise rent can be attribute of ID is unique so; can be implemented room. in the super class. Hence attribute is lodging.

Q.4 (b) Given that R1 is one to many and R2 is many to many. The one to many relationships are represented with entity set from Name is a function of super class. one side. Also, Name can be common/ This normally happens as each duplicate, so must be entity in the entity set can be implemented in super class. Salary associated with at most one entity of is a function of super class. Also, the other. salary is dependent on the category Therefore, the table is not formed and hence is implemented in the for R1 the tables are hence, formed subclass. for R2, E1 and E2. So, there are total of 3 tables. Q.2 (b) One table for E1, two table for Q.5 (c) E2(A21, A22 and A23). We need to If (2, 4) is deleted then 2 is the make a separate table for multi- primary key but in (5, 2) and (7, 2), valued attribute to satisfy minimum 2 is the foreign key so these must be 1NF condition. deleted. The primary key for (5, 2) Now, Relation table can be merged and (7, 2) is 5 and 7 respectively with (A21, A23). Tables are: but in (9, 5), 5 is the foreign key so it a) E1(A11, A12, A13) is also deleted. b) E21(A11,A21,A22) and c) E22(A21, A23). Q.6 (b) Number of tables = 3 Minimum No of tables required = 3 = {M, P, N} Since Cardinality of R1= Q.3 (c) N:1 It will never become a table. It is many to many. Rent cannot be And Cardinality of R2 = 1:N It will an attribute of room or person never become a table. entities lone. If depending on number of persons sharing a room Q.7 (a) the rent for each person for the room will be different.

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission Since P2 depends on P1, the only key The M : 1 relationship holds value, so merging P and M in one between two entities E1 and E2, in result will lead to non-normalized which each tuple from E2 is in tables. This needs to be removed relation with many tuples of E1. One without the loss to the information tuple from E1 is in relation with as P1 and P2 have primary key as P1 only one tuple of E2. It is given that and N1 and N2 has primary key participation from both the sides is as....N1. total and the cardinality of E1 is Therefore, the attribute set of table is greater than E2. {M1, M2, M3, P1}

Q.8 (c)

Option ‘A’ is correct as multivalued attribute e.g. phone no (attribute) Therefore, every entity E1 is Option ‘B’ is also correct. associated with exactly one entity in Option ‘D’ ‘Null’ values are allowed E2. in a row of relational database (Null value are constraints only for primary key As in 1NF also we remove multivalued attribute

Q.9 (∴4) Option ‘C’ is incorrect. Key in E1 is a11 Key in E2 is a21 Key in E3 is a31 Key in R12 will be a11+a21 since it is m:n relationship. Since R13 is 1:n relationship, it cannot be a table. So the minimum number of tables needed is 4.

Q.10 (c) Entity sets A,B Relationship set R Relation R merges with that of A.

• Many to one relationship set can merge towards entity set ‘A’. • Partipation towards A side can be total partial.

Q.11 (a)

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission 2 DATABASE DESIGN: FUNCTIONAL DEPENDENCIES & NORMALIZATION

Q.1 Given the following relation instance a) A functionally determines B and X Y Z B functionally determines C 1 4 2 b) A functionally determines B and 1 5 3 BS does not functionally 1 6 3 determine C 3 2 2 c) B does not functionally Which of the following functional determine C. dependencies are satisfied by the d) A does not functionally instance? determine B & B does not functionally determine C [GATE – 2002] a) XY→Z and Z→Y b) YZ→X and Y→Z Q.5 Relation R is decomposed using a c) YZ→X and X→Z [GATE – 2000] set of functional dependencies F, d) XZ→Y and Y→X and relation S is decomposed using Q.2 Consider a schema R (A, B, C, D) another set of functional with Functional dependencies AB dependencies G. One decomposition and CDThen the decomposition of is definitely BCNF, the other is R into R1 (AB) and R2 (CD) is definitely 3NF, but it is not known a) dependency preserving and which is to make a guaranteed lossless join identification, which one of the b) lossless join but not dependency following tests should be used on preserving the decompositions? (Assume that c) dependency preserving but not the closures of F and G are available) lossless join a) Dependency-preservation d) not dependency preserving and b) Lossless - join not lossless joins c) BCNF definition [GATE – 2001] d) 3NF definition [GATE – 2002] Q.3 R (A, B, C, D) is a relation. Which of the following does not have a Q.6 Relation R with an associated set of lossless join, dependency preserving functional dependencies F is BCNF decomposition? decomposed into BCNF. The redundancy (arising out of functional dependencies) in the resulting set of c)a) ABA→ B, C,B→CD C AD relations is d)b) A→B,A BCD B→C, C→D a) Zero → → [GATE – 2001] → b) More than zero but less than that Q.4 From the following instance of a of an equivalent 3NIF relational schema R (A, B, C), we can decomposition conclude that c) Proportional to the size of F A B C d) Indeterminate 1 1 1 [GATE – 2002] 1 1 0 2 3 2 Q.7 Consider the following functional 2 3 2 dependencies in a database:

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission Q.10 attributes empcode (unique), name, Data_of Birth→Age street,A relation city, Empdtlstate and is definedpincode. withFor Age→Eligibility any pincode, there is only one city Name→Roll_number me and state. Also, for any given street, Roll_number→Name city and state, there is just one Course_number(Roll number; →Course_naCourse number) pincode. In normalization terms, Course_number→Instructor relation in The relation (Roll_number; Name, a) 1NF only Date_of→Grade birth, Age) is b)Empdtl 2NF isand a hence also in 1NF a) in second normal form but not in c) 3NF and hence also in 2NF and third normal form 1NF b) in third normal form but not in d) BCNF and hence also in 3NF, 2NF BCNF an 1NF c) in BCNF [GATE-2004] d) in none of the above A table has fields Fl, F2, F3, F4, F5 [GATE-2003] Q.11 with the following functional

dependencies Q.8 Consider the following relation schema pertaining to a student’s In terms of Normalization, this table database: F1→F3, F2→F4, (F1, F2) →F5 Student (rollno, name, address) is in a) 1 NF b) 2NF coursename) c) 3 NF d) None of these Enroll (rollno, courseno, [GATE-2005] where the primary keys are shown underlined. The number of tuples in Q.12 Which one of the-following the stu statements about normal forms is 120 and 8 respectively. What are the false? maximumdent and and minimum Enroll number tables are of a) BCNF is stricter than 3NF tuples that can be present in b) Lossless, dependency-preserving (Student * decomposition into 3NF is natural join? always possible a) 8, 8 Enroll), whereb) 120, ‘*’ 8denotes c) Loss less, dependency-preserving c) 960, 8 d) 960, 120 decomposition into BCNF is [GATE-2004] always possible d) Any relation with two attributes Q.9 The relational schema Student is in BCNF Performance (name, course No, roll [GATE – 2005] No, grade) has the following functional dependencies Q.13 Consider a relational schema R = (A, Name, courser no grade, Roll No, course no grade following functional dependencies Name roll No → hold:B, C, D, {A E, andB, BC H) on whichC, and the D A}. Roll No name → What are the candidate keys of R? The highest→ normal form of this → →D, E → → relation→ schema is a) 2 NF b) 3 NF a) AE, BE c) BCNF d) 4 NF b) AE, SE, DE c) AEH, BEH, BCH [GATE – 2004] [GATE – 2005] d) AEH, BEH, DEH

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission Q.14 In a schema with attributes A, B, C, D a) Any relation with two attributes is in BCNF dependencies are given b) A relation in which every key has and E following set of functional only one attribute is in 2NF c) A prime attribute can be A → B transitively dependent on a key A → C in a 3NF relation CD → E d) A prime attribute can be WhichB → D of the following functional transitively dependent on a key dependenciesE → A is NOT implied by the in a BCNF relation above set [GATE – 2007]

Q.19 Consider the following implications a) CD→AC b) [GATE BD→CD-2005] relating to functional and multi c) BC→CD d) AC→BC valued dependencies given below, which may or may not be correct. Q.15 Consider the relations r1(P,Q,R) and

r2 (R,S,T) with primary keys P and R

respectively. The relation r1 i) If A→→B and A→→C then A→BC contains 2000 tuples and r2 contains 2500 tuples. The maximum iv)ii) If If A→I3 and A→C then A→→4BC iii) If A→→BC and A→B then A→C Size of the join r1 r2 is : a) 2000 b) 2500 implicationsA→BC and are A→Bvalid? then A→→C c) 4500 ⋈ d) 5000 a)Exactly 0 how many of b)the 1 above [GATE-2006] c) 2 d) 3 [GATE-2007] Q.16 Consider a relation R with five attributes V, W, X, Y, and Z. Q.20 Let R (A, B, C, D) be a relational The following functional schem a with the following dependencies hold functional dependencies:

Which of the following: VY→W, WX→Z,is a The decomposition of R into (A, B), candidateand ZY→V. key for R? (B,A →B, C), B→C,(B, D) C→D and D→B. a) VXZ b) VXY a) Gives a lossless join, and is c) VWXY d) VWXYZ dependency preserving [GATE-2006] b) Gives a lossless join, but is not dependency preserving Q.17 The following functional c) Does not give a lossless join, but dependencies are given AB CD, AF is dependency preserving F, C G, F A d) Does not give a lossless join and Which one of the following→ options is not dependency preserving is→ D,false? DE → → →E, G → [GATE-2008] a) {CF} + b) {BG} + = {ABCDG} Q.21 Let R (A, B, c) {AF} + = {ACDEFG} relational schema in which the d) {AB} + = {ABCDFG} following functionalC, D, E, P,dependencies G) be a = {ACDEFG} [GATE – 2006] are known to hold:

Q.18 Which one of the following The relational schema R is statements is false? a)AB→CD,DE→P,C→E,P→C in BCNF and B→G.

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission b) in 3NF, but not in BCNF 3. BankAccount_Number: unique c) iri 2NF, but not in 3NF account number at the bank. A d) not in 2NF student can have multiple [GATE-2008] accounts or joint accounts. This attributes stores the primary Q.22 Consider the following relational account number schemas for a library database Book 4. Name: Name of the Student (Title, Author, Catalog no, Publisher, 5. Year, Price) hostel Collection (Title, Author, Catalog no) WhichHostel_room: of the following Room number options of isthe Within the following functional incorrect? dependencies a) BankAccount_Number is a 1. Title Author Catalog_no candidate key 2. Catalog no Title Author b) Registration_Number can be a Publisher Year→ primary key 3. Publisher Title →Year Price c) UID is a candidate key if all Assume {Author, Title} is the key students are from the same for both schemas. Which→ of the country following statements is true? d) If S is a super key such that S UID a) Both Book and Collection are in ∩ is NULL then S UID is also a BCNF super key b) Both Book and Collection are in [GATE – 2011] 3NF only c) Book is in 2NF and Collection is Q.25 Which of the following is true? 3NF d) Both Book and Collection are in BCNF a) Every relation in 3 NF is also in 2NF only b) A relation R is in 3NF if every non-prime attribute of R is fully [GATE – 2008] functionally dependent on every Q.23 The following functional key of R dependencies hold for relations R c) in BCNF is also in B A, A C 3 NF The relation R contains 200 tuples d) NoEvery relation relation can be in both BCNF and(A, B, theC) and relation S (B, D, SE) contains→ →100 and 3NF tuples. What is the maximum [GATE – 2012] number of tuples possible in the Common Data for Questions Q.26 and a) 100 b) 200 Q.27: c)natural 300 join R ⋈ S d) 2000 [GATE – 2010] Fields of R contain only atomic values. F = RelationG, AR hasBC, eight B attributesA, ABCDEFGH.F Q.24 Consider a relational table with a set of functional dependencies. So that F is single record for each registered exactly{CH the set of FD’sCFH, that E hold for R.EG} is a student with the following attributes: Q.26 1. Registration_Number: Unique relation R has? registration number for each a)How 3 many candidate b) 4 keys do the registered student 2. UID: Unique Identity Number, c) 5 d) 6 unique at the national level for [GATE – 2013] each citizen

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission Q.27 The relation R is key, the following is a valid table a) In INF, but not in 2NF definition. b) In 2NF, but not in 3NF c) In 3NF, but not in BCNF d) In BCNF CREATE TABLES ( [GATE – 2013] a INTEGER, d INTEGER, Q.28 The maximum number of super keys e INTEGER, WhichPRIMARY one KEY (d),of the following statementsFOREIGN KEY (a) references R) for the relation schema R(E, F, G, H) [GATE- 2014] with E as the key is ______Q.29 b) Both S1 an is CORRECT? relation as shown below: a) S1 is TRUE and S2 is FALSE. StudentGiven Student an instance Student of the StudentSTUDENTS d S2 are TRUE. CPI ID Name Email Age c) S1 is FALSE and S2 is [GATE TRUE.- 2014] d) Both S1 and S2 are FALSE. 2345 Shankar shankar@math X 9.4 Q.33 Consider the following two 1287 Swati swati@ee 19 9.5 statements:- 7853 Shankar shankar@cse 19 9.4 S1: - 9876 Swati swati@mech 18 9.3 valued attributes is in 1NF, 2NF, 8765 Ganesh ganesh@civil 19 8.7 3NF,Every and table BCNF with two single For (StudentName, StudentAge) to S2: ABC, D C is a minimal be a key for this instance, the value cover for the set of FD’s ABC, X should NOT be equal to ______. D  E, EC [GATE-2014] Which one of the following is E, AB E, E Q.30 A prime attribute of a relation a) scheme R is an attribute that appears b) CORRECT? a) In all candidate keys of R. c) S1 is TRUE and S2 is FALSE. b) In some candidate key of R. d) Both S1 and S2 are TRUE. c) In a foreign key of R. S1 is FALSE and S2 [GATEis TRUE.-2014] d) Only in the primary key of R. Both S1 and S2 are FALSE. Q.34 Consider the relation X(P, Q, R, S, T, [GATE -2014] U) with the following set of Q.31 functional dependencies F = {{P, R} {S, T}, {P, S, U} {Q, R}} setConsider of thefunctional relation schemedependencies R=(E, Which of the following is the trivial F, G, H,G, I, F J, K, L, M, N) and theM, given LN} functional dependency in F+, where on R. What is the key for R? F+ is closure of F? {EF IJ, EH KL, K a) {P, R}{S, T} b) {P, R}{R, T} b) {P, S}{S} c) {P, S, U}{Q} a) {E,F} b)[GATE {E, F,-H} 2014] [GATE- 2015] c) {E, F, H, K, L} d) {E} Q.32 Given the following statements: Q.35 Which of the following is NOT a S1: A foreign key declaration can super key in a relational schema always be replaced by an with attributes V, W, X, Y, Z and equivalent check assertion in primary key V Y? SQL. a) VXYZ b) VWXZ S2: Given the table R(a,b,c) where a c) VWXY d) VWXYZ and b together form the primary [GATE- 2016]

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission Q.36 A database of research articles in a journal uses the following schema. Q.38 Consider the following four (Volume, Number, StartPage, relational schemas. For each schema, all non-trivial functional The primary key is (Volume, dependencies are listed. The EndPage, Title, Year, Price) underlined attributes are the the following functional respective primary keys. dependenciesNumber, StartPage, exist in EndPage)the schema. and (Volume, Number, StartPage, Schema I: Registration (rollno, Page)  Title courses) (Volume, Number)  Year -valued (Volume,End Number, Startpage, attribute containing the set of  Price coursesField ‘courses’ a student is a has set registered for. The database is redesigned to use Non-trivial functional dependency: theEndPage) following schemas. (Volume, Number, StartPage, SchemaRollno → II: courses Registration (rollno, (Volume, Number, Year) courseid, email) WhichEndPage, is Title,the weakest Price) normal form Non-trivial functional dependencies: that the new database satisfies, but the old one does not? a) 1NF b) 2NF rollno, coursed → email c) 3NF d) BCNF Schemaemail → III:rollno Registration (rollno, [GATE -2016] courseid, marks, grade) Non-trivial functional dependencies: Q.37 The following functional dependencies hold true for the relational schema R{V,W,X, Y,Z}: rollno, coursed → marks, grade VW→ Schemamarks → IV: grade Registration (rollno, VW→ X courseid, credit) Non-trivial functional dependencies: Y→ VX

YZ→ Which of the following is irreducible rollno, coursed → credit equivalent for this set of functional Whichcourseid on →e ofcredit the relational schemas dependencies? above is in 3NF but not in BCNF? VW→ VW→ a) Schema I b) Schema II VX→ WX→ c) Schema III d) Schema IV a) b) YV→ YV→ [GATE-2018] YZ→ YZ→

VW→ VW→ VX→ WX→ c) YV→ d) YV→ YX→ YX→ YZ→ YZ→ [GATE -2017]

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission ANSWER KEY:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 (b) (c) (c) (b) (c) (a) (d) (a) (b) (b) (a) (c ) (d) (b) (b) 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 (b) (c) (d) (c) (c) (d) (c) (a) (a) (c) (b) (a) 8 19 (b) 31 32 33 34 35 36 37 38 (b) (b) (a) (c) (b) (b) (a) (b)

EXPLANATIONS

Q.1 (b) This means all are dependent on From the table given above, the B each other. functional dependency is satisfied by the instance. We can say this by the following: Now, A→ Band B→ C Y is functionally dependent on Z. This implies, A→ C or we can say the on X. AB→ C This is referred to as multi valued Q.4 Similarly,C(b) →AD independency.→YZ is functionally dependent Let’s consider A and B first. Q.2 (c) We need to check two parameters for the solution 1. Lossless join 2. Dependency preserving Value of relation A is equal to the 1. Lossless join value of the relation B as A and B R (CD) R (AB) 1 2 1 follows the same pattern. The value also R (CD) R (CD) 1 2 1 of A does not change where the But(AB)⋀R we know ⟶that Functional value of B does not change. dependencies(AB)⋀R A B⟶ and C D Let’s now consider B and C. Hence, the statement above is not possible. → → R1 {ABCD) is not a lossless join. 2. Dependency preserving Since,⟶ R1 2(CD) R(ABCD) Value of relation B is not equal to It is dependency preserving. the value of the relation B as B and C (AB)⋁R ⟶ do not follow the same pattern. The Q.3 (c) value of C changes where the value The solution exhibits as another of B does not change. case of multi valued dependency. Here, the given relation is R (A,B,C, D). Q.5 (c)

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission Relation R is decomposed by maximum 8 tuples in natural join functional dependency F. and rno of Enroll foreign key Relation S is decomposed by references to student. So minimum functional dependency G. also 8 tuples in natural join. One of the decompositions is in BCNF and other is in 3NF. Q.9 (b) We cannot use 3NF definition since Check for 1NF, if a relation is in BCNF then it is also 1NF says that the attributes should in 3NF. not be repeated. Here we can see We cannot use lossless-join because that the attributes are not repeated. both decompositions are lossless. Condition is satisfied hence the We use BCNF definition so that 3NF relation schema is in 1 NF. fails on this test. Check for 2NF, 2NF says that there should not be Q.6 (a) any partial dependency. Here it can According to the problem, R is be seen that there is no partial associated with functional dependency. Condition is satisfied dependencies, so this clearly and hence the relation is in 2NF. indicates that relation R is in 3NF, Check for 3NF, i.e., third normal form. The property Last two lines of the code show of 3NF says that there are few or transitive dependency. no error are left and therefore, redundancy (arising out of functional dependencies) in resulting ThisName is →Roll not against No the conditions of set of relations is negligible or 0 in 3NFRoll No→and hence name it is in 3NF. most cases. Check for higher forms, Since the conditions of 3NF are Q.7 (d) satisfied. Relation (Roll_number, Name, Date- of-birth, Age) Q.10 (b) Fd's which member of the relation It is in 2NF. Date-of- For 2NF, all non prime attributes should be fully functionally birth→Age dependent on key. Key is empcode. CandidateName→Roll_number keys {Name, date-of- Key contains only one attribute, birth},Roll_number→Name {Rollnumber, date-of-birth} hence no partial dependency, but Date-of- is partial there is transitive dependency. So it dependency which not allowed in is not in 3 NF. 2NF. Highestbirth→Age NF of given relation 1 NF. Q.11 (a) key is F1F2 Q.8 (a) are partial dependencies. Student (rno, name, address) {rno} unique. Q.12 (c)F1→F3,F2→F4 Enroll (rno, cno, Cname) {rnocno} The statement false is Lossless; unique. dependency-preserving Each record of Enroll can be decomposition into BCNF is not mapped one record of student based always possible. on natural join condition. So

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission Lossless, dependency preserving with two attributes gets into Boyce decomposition is possible in certain code normal form. cases only. It is important to note Statement (B) A relation in which that BCNF is not dependency every key has only one attribute is preserving in all cases but in some 2NF is true as 2NF allows only the cases only. relation where a key has only one attribute. Q.13 (d) Statement (C) A prime, attribute can The keys AEH, BEH and DEH be transitively dependent on a key in generate the (A,B,C,D,E,H) considering a 3NF relation is also true as„ prime the functional dependencies attribute has to be transitively { dependent on a key in 3NF. So, AEH, BEH and DEH are the Statement (D) A prime attribute candidateA → B, BC keys → D, ofE →R C, because and D → all A} of can be transitively dependent on a these generate {A, B, C, D, E, H}. key in a BCNF relation is false as this is a feature of 3NF and not BCNF. Q.14 (b) Apply membership test for all the Q.19 (c) given Functional Dependencies. i) 1. not valid CD+ = CDEAB ii) If A→→B and A→→C then A→BC 2. CD → AC BD+ = BD iii) If A→B and A→C then A→BC, i.e. BD→CDBD cannot derive CD and hence nottherefore valid A→→BC is also valid. is not implied Similarly for rest two iv) If A→→BC and A→B, then A→C can be done. Note:If A→BC Every and FD A→Bis a specialthen A→C, case of Q.15 (b) multitherefore-valued dependency.A→→C also valid. Relation r1 contains 2000 tuples, Q.20 (c) and r2 contains - 2500 tuples. (A,B) and (B,C) have common Maximum common R values are attribute possible for join of r1 and r2 is 2000. for (B,C). Hence ABCas B. Duecan tobe B→C, loss B is lesslya key Q.16 (b) + decomposed into (A,B) and (B,C). (VY) = VYW (A, B, C) (B, D), common attribute is B. + (VYX) = VYV,VXZ We have a dependencies & WX hence B is a key for (B, D).

So,B →D decomposition is a FD (via of B→C, (A, B, C→D), C, D) into and keys. ZY→V →Z (A, B, C) (B, D) is lossless. Thus the ∴ VYX, ZYX and WXY are candidate given decomposition is lossless. Q.17 ⇒(c) VXY is candidate key for R. The given decomposition is also AF will give A and F. Also it gives D dependency preserving: and E because AFD and FE. But we cannot get C and G. present in (B,A→B D), is and is present in (A, B), B→C is Q.18 (d) via (B, C), D→B is present in Statement (A) Any relation with C→D is indirectly present two attributes is in BCNF is true as Q.21 (d) C→B in (B, C) and B→D in (B, D). with the rules of BCNF, any relation

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission Not in 2NF because here candidate key is AB and in FD's proper subset of C.K. determine the non prime attribute i.e.

Q.22 (c) B→G. We will observe that if all the non-

key fields are fully dependent on a According to relation between the whole key then a table would be different normal forms i.e.,BCNF is formed in the Second normal form more restricted than 3 NF and 3 NF (2NF). is more restricted than 2 NF and so This table will be in the 3NF only on. when non-key fields are Consider option (a): independent on a whole key than a The statement is given which is table. Alternatively, Relation Book: wrong because every relation which transitivity dependency by 1, 2, 3 is in 3rd normal form it is not statements as given, hence the necessary that those will be in BCNF relation Book is in 2NF. form. Hence, this is false. Relation Collection: it is in 3NF as Consider option (b): there is fully transitive dependency. When every non-prime attribute of Therefore Book is in 2NF and R is fully functionally dependent on Collection is in 3NF.s every key of R. Then, that relation is in 2 NF not in 3 NF. Q.23 (a) Consider option (c): B A where R (A, B, C) and S (B, D, Every relation which is in BCNF, then E), A C it is confirmed that it is also in 3 NF. → R contains 200 tuples and S contains Consider option (d): → 100 tuples. This statement is wrong because the relation can be in both BCNF and 3 So, R = 200 tuples and S = 100 tuples NF. Natural join ⋈=R ⋈ S = π[σRXS] we can say distinct equality between Q.26 (b) So, R ⋈ S = 100 [common is both or Relation contain 8 attributes ABCDEFGH Q.24 (a)all common attributes] Candidate key cannot be common. BankAccount_Number is not a CandidateF={CH→G, Key A→BC, : AD, ED, B→CFH, BD, FD E→A, candidate key. As per the question F→EG} “A student can have multiple accounts or joint accounts. This attributes Q.27 (a)∴Answer is (b) 4. stores the primary account number”. Relations is in 1 NF, but not in 2NF If two students have a joint account because it is atomic and not in 2 NF and if the joint account is their because prime attributes of relation primary account, then BankAccount_Number value cannot A BC written as (a) A B uniquely identify a row. (b)Ais {A, B,c D, E, F] In→ option⟹ (b) Violates definition→ of 2 Q.25 (c) NF, pot→ a prime attribute should

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission derive from, candidate key or not be S1: Table with two single valued derived from a prime attribute. attributes (A, B) will have key as Option (c) Wrong answer - Because either A or B or AB. relation is not in 2NF. The FD’s that are possible always Options (d) Relation is not in 2NF will have key on the LHS. So it is in it is not in 3NF & BCNF. BCNF. Answer is (a) in 1 NF, but not in 2NF. S2: The minimal cover cannot have ⟹ ABE. So S2 is false. Q.28 (8) Maximum no. of possible super keys Q.34 (c) for a table with n attributes = 2^(n-1) And FD: XY is trivial if Y is subset of X. Q.29 (19) (StudentName, StudentAge) is a Q.35 (b) key Super Key=Key+0 (or) more Shankar X  attributes. here X should not be 19 Shankar 19 Key = VY Super Key = VY + more attributes

a) VXYZ = VY + XZ  Super Key Q.30 (b) b) VWXZ = doesn’t contain Key “VY” An attribute is called prime attribute  if is part of any candidate key. Not a Super Key  c) VWXY = VY + WX Super Key d) VWXYZ = VY + WXZ  Super Key Q.31 (b) The missing attributes on the right

hand side of the FDs are E, F, H. Q.36 (b) Old database  in 1NF These three attributes together can  identify all other attributes. So {E, F, New Database in BCNF. So the weakest normal form that the H} is the key. new database satisfies, but the old one does not is 2NF Q.32 (b)

S1 is FALSE. A foreign key declaration cannot always be Q.37 (a)

replaced by an equivalent check assertion in SQL. {V→W,VW→X,Y →V,Y→X,Y →Z} S2: CREATE TABLE S ( We extraneousredundant from FD VW→X from above set a INTEGER, {V→W, V→X, Y→V, Y→X,Y→Z} d INTEGER, is minimal cover. Y→X is e INTEGER, Q.38 {V→W,V→X,Y→V,Y→Z}(b) PRIMARY KEY (d), Schema I: FOREIGN KEY (a) references R) Registration (rollno, courses) rollno S2 referenced attribute set (set of key attribute used for foreign reference) and referencing attribute For the given schema Registration set (set of foreign key attribute) ‘rollno’→ courses is a primary key. must be same. Left-side of the functional dependency is a . so, Q.33 (a) Registration is in BCNF.

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission Schema II: The candidate key is (rollno + Registrstion (rollno, courseid, email) courseid).

courseid is part of the key (prime

attribute)In the FD,and courseidcredit is non → -prime. credit, Fromrollno, the courseid given schema → email the email → rollno So, it is a partial dependency. candidate key is (rollno + courseid). The schema is violating 2NF. There is no part of the key in the left hand of the FD’s so, it is in 2NF. il is non-prime attribute but rollno is a primeIn the FDattribute. email→rollno, ema So, it is not a transitive dependency. No transitive dependencies so, the schema is in 3NF.

email is not a superkey. So,But it in is the violating second BCNF. FD email→rollno, Hence, the schema Registration is in 3NF but not in BCNF.

Schema III: Registration (rollno, courseid, marks, grade)

Forrollno, the courseid schema the→ marks, candidate grade key is (rollnomarks → + gradecourseid). There are no part of the keys are determining non-prime attributes. So, the schema is in 2NF.

attributes marks and grade are non- prime.In the FD marks → grade, both the So, it is a transitive dependency. The FD is violating 3NF. The schema Registration is in 2NF but not in 3NF.

Schema IV: Registration (rollno, courseid, credit)

rollno, courseid → credit courseid → credit

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission 3 STRUCTURED QUERY LANGUAGE (SQL)

Q.1 In SQL, relations can contain null Students:(Roll_number,Name,Data_o values, and comparisons with null f_birth) values are treated as unknown. Courses:(Course_number,Course_na Suppose all comparisons with a null me,Instructor) value are treated as false. Which Grades: (Roll_number, of the following pairs is not Course_number, Grade) equivalent? Select distinct Name a) X = 5 AND not (not (x = 5)) From Students, Courses, Grades b) X = 5 AND x > 4 and x < 6, where Where Students, Roll_number = x is an integer Grades. Roll_number c) And Courses.Instructor = Korth d) None of the above And Courses.Course_number = X ≠5 AND not (x =[GATE 5) – 2000] Grades. Course_ number And Grades. Grade = A Q.2 Given relations r (w, x) and s(y, z), Which of the following sets is the result of Select distinct w, x computed by the above query? From r, s Is guaranteed to be same a) Names of students who have got as r, provided an A grade in all courses taught a) r has no duplicates and s is non- By Korth empty b) Names of students who have got b) r and _s have no duplicates an A grade in all courses c) s has no duplicates and r is non- c) Names of students who have got empty an A grade in at least one of the d) r and s have the same number of courses taught by Korth tuples d) None of the above [GATE – 2000] [GATE – 2003] Q.3 Consider the following SQL query select distinct a1, a2,……..an Q.5 The employee information in a from r1, r2…… rm company is stared in the relation Employee (name, sex, salary, dept, Name) querywhere ρis equivalent to which of the Consider the following SQL query: followingFor an arbitrary relational predicate algebra ρ, this Select dept Name expressions? From Employee Where sex = ‘M’ a) ∏σρ ()r12 ×× r ..... × r m a1 ,a 2, ....,a n Group by dept Name Having avg (salary) > b) ∏ σρ ( r1 r2 m) a1 ,a 2, ....,a n (Select avg (salary) from Employee)

c) ∏ σρ ( r1⋈ 2 ⋈…..⋈ rm) It returns the name of the a1 ,a 2, ....,a n department in which d) ∏ σρ ( r1 ∪ r2 ∪…..∪ rm) a) The average salary is more than a1 ,a 2, ....,a n the average salary in the company ∩ r ∩…..∩ [GATE r -2003] b) The average salary of male employees is more than the Q.4 Consider the set of relations shown average salary of all male below and the SQL query that follows:

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission employees in the company Update T1 set marks = marks +5 c) Time average salary of male Select avg(marks) from T1 employees is more than the What is the output of the select average salary of employees in statement? the same department a) 18.75 b) 20 d) The average salary of male c) 25 d) Null employees is more than the [GATE-2004] average salary in the company [GATE – 2004] Q.8 Consider two tables in a relational database with columns and rows as Q.6 A relational database contains two follows: tables student and department in Table : Student which student table has columns Roll_no Name Dept_id roll_no, name and dept_id and 1 ABC 1 2 DEF 1 department table has columns 3 GHI 2 dept_id and dept name. The 4 JKL 3 following insert statements were executed successfully to populate Table : Department the empty tables: Dept_id Dept_name Insert into department values (1, 1 A Mathematics') 2 B Insert into department values (2, 3 C 'Physics') Roll_no is the primary key of the Insert into student values (1, Student table. Dept_id is the primary 'Navin', 1) key of the Department table and Insert into student values Student. Dept_id is a foreign key (2,`Mukesh', 2) from Department. Dept_id Insert into student values (3, `Gita', What will happen if we try to 1) execute the following two SQL How many rows and columns will statements? be retrieved by the following SQL i) update Student set Dept_id = statement? Select * from student, Null where Roll no = 1 department ii) update Department set Dept_id = a) 0 row and 4 columns Null where Dept_id = 10 b) 3 rows and 4 columns a) Both (i) and (ii) will fail c) 3 rows and 5 columns b) (i) will fail but (ii) will succeed d) 6 rows and 5 columns c) (i) will succeed but (ii) will fail [GATE-2004] d) Both (i) and (ii) will succeed [GATE-2004] Q.7 A table T1 in a relational database has the following rows & columns: Q.9 A company maintains records of roll no. marks sales made by Its salespersons and 1 10 pays them commission based on each individual's total sales made in 2 20 a year. This data is maintained in a 3 30 table with following schema: 4 Null salesinfo= (salespersonid, totalsales, The following sequence of SQL commission) statements was successfully executed In a certain year, due to better on table T1. business results, the company

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission decides to further reward its sales these items. Supply = (supplierid, persons by enhancing the itemcode) commission paid to them as per the Inventory = (itemcode, warehouse, following formula: stocklevel) If commission < = 50000, enhance it For a specific information required by 2% by the management, following SQL If 50000 < commission < = 100000, query has been written enhance it by 4% Select distinct STMP.supplierid If commission > 100000, enhance it From Supply as STMP by 6% Where not unique (Select ITMP. The IT staff has written three supplierid different SQL scripts to calculate From Inventory, Supply as ITMP enhancement for each slab, each of Where STMP.supplierid = these scripts is to run as a separate ITMP.supplierid transaction as follows: And ITMP.itemcode = T1 : Update salesinfo Inventory.itemcode Set commission = commission *1.02 And Inventory.warehouse = Where commission < = 50000; `Nagpur'); T2 : Update salesinfo For the warehouse at Nagpur, this Set commission = commission * 1.04 query will find all suppliers who Where commission> 50000 & a) do not supply any item commission b) supply exactly one item is < = 100000; c) supply one or more items T3 : Update salesinfo d) supply two or more items Set commission = commission * 1.06 [GATE-2005] Where commission > 100000; Which of the following options of Q.11 The relation book (title, price) running these transactions will contains the titles and prices of update the commission of all different books. Assuming that no salespersons correctly? two backs have the same price, what a) Execute T1 followed by T2 does the following SQL query list? followed by T3 Select title b) Execute T2, followed by T3; T1 From book as B running concurrently throughout Where (select count (*) c) Execute T3 followed by T2; T1 From bock as T running concurrently throughout Where T.pric>B.price) < 5 d) Execute T3 followed by T2 a) Titles of the four most expensive followed by T1 books [GATE-2005] b) Title of the fifth most inexpensive book Q.10 In an inventory management system c) Title of the fifth most expensive implemented at a trading corporation, book there are several tables designed to d) Titles of the five most expensive hold all the information. Amongst books these, the following two tables hold [GATE – 2005] information on which items are Directions for Question Q.12 to supplied by which suppliers, and Q.13 which warehouse keeps which Consider a database with three items along with the stock-level of relation instances shown below. The

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission primary keys for the Drivers and intersect cars relation are did and cid select R.did respectively and the records are from Cars C, Reserves R stored in ascending order of these where primary keys as given in the tables. R.cid=C.cid and C.colour No indexing is available in the = 'green') database. a) Karthikeyan, Boris D: Drivers relation b) Sachin, Salman did dname Rating age c) Karthikeyan, Boris, Sachin 22 Karthikeyan 7 25 d) Schumacher, Senna 29 Salman 1 33 [GATE-2006] 31 Boris 8 55 32 Amoldt 8 25 58 Schumacher 10 35 Q.13 Let n be the number of comparisons 64 Sachin 7 35 performed when the above SQL 71 Senna 10 16 query is optimally executed. If 74 Sachin 9 35 linear search is used to locate a 85 Rahul 3 25 tuple in a relation using primary 95 Ralph 3 53 key, then n lies in the range R : Reserves relation a) 36 - 40 b) 44 - 48 did cid day c) 60 - 64 d) 100 - 104 22 101 10/10/2006 [GATE-2006] 22 102 10/10/2006 22 103 08/10/2006 Q.14 Consider the relation enrolled 22 104 07/10/2006 (student, course) in which (student, 31 102 10/11/2006 course) is the primary key, and the relation paid (student, amount) 31 103 06/11/2006 where student is -the primary key. 31 104 12/11/2006 Assume no null values and no 64 101 05/09/2006 foreign keys or integrity constraints. 64 102 08/09/2006 Given the following four queries: 74 103 08/09/2006 Query1: select student from enrolled where student in (select student C: Cars relation from paid) cid cname colour Query2: select student from paid 101 Renault blue where student in (select student 102 Renault red from enrolled) 103 Ferrari green Query3: select E. student from 104 Jaguar red enrolled E, paid P where E. student = P. student

Query : Select student from paid Q.12 What is the output of the following 4 where exists (Select * from enrolled SQL query? where enrolled. student = paid. select D.dname student) from Drivers D Which one of the following where D.did in ( statements is correct? select R.did a) All queries return identical row from Cars C, Reserves R sets for any database where R.cid=C.cid and b) Query and Query return C.colour 2 4 identical row sets for all = 'red'

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission but there exist 5 Assigning rank with a pure databases for Which Query1, and relational query takes less time Query2 return different row sets than scanning in decreasing c) There exist databases for which balance order assigning ranks Query3 returns strictly fewer using ODBC. rows than Query2 Which two of the above statements d) There exist databases for which are correct? Query4 will encounter an a) 2 and 5 b) 1 and 3 integrity violation at runtime c) 1 and 4 d) 3 and 5 [GATE – 2006] [GATE – 2006]

Consider the table Q.15 Consider the relation account Q.16 employee (customer, balance) where customer (empld, name, department, salary) is a primary key and there are no and the two queries Q1, Q2 below. null values. We would like to rank Assuming that department 5 has customers according to decreasing more than one employee, and we balance. The customer with the want to find the employees who get largest balance gets rank I. Ties are higher salary than anyone in the not broken but ranks are skipped: If department 5, which one of the exactly two customers have the statements is true for any arbitrary largest balance they each get rank 1 employee table? and rank 2 is not assigned. Q1: Select e.empld From employee e Where not exists (Select*from employee s where s.department="5"ands.salary>=e.sal ary) Q2: Select e.empld From employee e Where e.salary > any (Select distinct salary From employee s Where s.department= "5") a) Q1, is the correct query b) Q is the correct query 2 Consider these statements about c) Both Q1 and Q2 produce the same answer Query1, and Query2 d) Neither Q1, nor Q2 is the correct 1 Query1, will produce the same query row set as Query2 for some but [GATE – 2007] not all databases. 2 Both Query1, and Query2 are Directions for Question Q.17 to Q.18: correct implementation of the Consider the following relational schema: specification. Student(school-id, sch-roll-no, sname, 3 Query1, is a correct saddress) implementation of the School(school-id, sch-name, sch-address, specification but Query2 is not. sch-phone) 4 Neither Query1, nor Query2is a Enrolment(school-id sch-roll-no, erollno, correct implementation of the examname) specification. ExamResult(erollno, examname, marks)

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission Q.17 What does the following SQL query | x Enrolment A x.school-id = I * 100 output? > 35} SELECT sch-name, COUNT (*) If a student needs to score more FROM School C, Enrolment E, than 35 marks to pass an exam, ExamResult R what does the query return? WHERE E.school-id C.school-id a) The empty set AND b) schools with more than 35% of E.examname = R.examname its students enrolled in some AND exam or the other E.Erollno = R.erollno c) schools with a pass percentage AND above 35% over all exams taken R.marks = 100 AND together S.school-id IN d) schools with a pass percentage (SELECT school-id FROM above 35% over each exam student GROUP BY school- [GATE-2008] id HAVING COUNT (*) > 200) Q.19 Consider a database table T GROUP By school-id containing two columns X and Y a) for each school with more than each of type integer. After the 200 students appearing in creation of the table, one record (X exams, the name of the school =1, Y =1) is inserted in the table. Let and the number of 100s scored M x and M Y denote the respective by its students maximum values of X and Y among b) for each school with more than all records in the table at any point 200 students in it, the name of in time. Using MX+1, 2*MY +1 the school and the number of respectively. It may be noted that 100s scored by its students each time after the insertion, c) for each school with more than values of MX and MY change. What 200 students in it, the name of will be the output of the following the school and the number of its SQL query after the steps mentioned students scoring 100 in at least above are carried out? one exam SELECT Y FROM T WHERE X = 7; d) Nothing; the query has a syntax a) 127 b) 255 error c) 190 d) 257 [GATE – 2011] Borrower Bank_Manage Loan_Amoun r t Q.20 Database table by name Ramesh Sunderajan 100000.00 Loan_Records is given below Suresh Ramgopal 5000.00 What is the output of the SQL query? Mahesh Sunderajan 7000.00 SELECT Count(*) [GATE-2008] FROM ( (SELECT Borrower, Bank_Manager Q.18 Consider the following tuple relational calculus query. FROM Loan_Records) AS S - NATURAL JOIN {x| - (SELECT {t|∃E ∈ExamResult Enrolment t=E.schoolB.erollnoid ∧|= Bank_Manager,Loan_Amount x Enrolment∧x.school B.examname id = t ∧= FROM Loan_Records) AS T); (∃B > 35)} |÷ |{x a) 3 b) 9 x.erollno ∧ c) 5 d) 6 x.examname ∧ B.marks [GATE – 2011]

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission SELECT clause S. Not all Common Data for Questions Q.21 and attributes used in the GROUP BY Q.22 clause need to appear in the Consider the following relations A, B and C: SELECT clause A. a) P and R b) P and S ID NAME AGE c) Q and R d) Q and S 12 Arun 60 [GATE – 2012] 15 Shreya 24 99 Rohit 11 Q.24 Given the following schema:- B. Employees (emp-id, first-name, ID NAME AGE last-name, hire-date, dept-id, 15 Shreya 24 salary) departments(dept-id, 25 Hari 40 dept-name,manager-id, location- 98 Rohit 20 id) C. You want to display the last names and hire dates of all latest hires in ID Phone Area 10 2200 02 their respective departments in the location ID 1700. You issue the 99 2100 01 following query:- Q.21 How many tuples does the result of SQL> SELECT last-name, hire-date the following relational algebra FROM employees expression contain? Assume that the WHERE (dept-id, hire-date)IN schema of (SELECTdept-id, A. C MAX(hire-date) a) 7 A∪B is the b)same 4 as that of A.Id>40⋁C.Id<15 FROM employees JOIN c) 5(A ∪ B)⋈ d) 9 departments USING [GATE-2012] (dept-id)

WHERElocation-id= 1700 Q.22 How many tuples does the result of GROUP BY dept-id); the following SQL query contain? What is the outcome? SELECT A. Id a) It executes but does not give the FROM A correct result. WHERE A. Age > ALL (SELECT B. b) It executes and gives the correct Age result FROM B c) It generates an error because of WHERE B. Name = 'Arun') pair wise comparison a) 4 b) 3 d) It generates an error because c) 0 d) 1 the GROUP BY clause cannot be [GATE – 2012] used with table joins in a sub

query. Q.23 Which of the following statements [GATE-2014] are true about an SQL query? Q.25 SQL allows duplicate tuples in P. An SQL query can contain a relations, and correspondingly HAVING Clause even If it does defines the multiplicity of tuples in not have a GROUP BY clause the result of joins. Which one of the Q. An SQL query can contain a following queries always gives the HAVING clause only if it has a same answer as the nested query GROUP BY clause shown below: R. All attributes used in the GROUP BY clause must appear in the

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission Select * from R where a in (select c) Names of all the employees with S.a from S) none of their customers having a a) Select R.* from R, S where 'GOOD' rating. R.a=S.a d) Names of all the employees with b) Select distinct R.* from R, S all their customers having a where R.a=S.a 'GOOD' rating. c) Select R.* from R, (Select distinct [GATE-2014] a from S) as S1 where R.a=S1.a Consider the following relations: d) Select R.* from R, S where Q.28 R.a=S.a and is unique R Student Roll. No Student Name [GATE-2014] 1 Raj 2 Rohit Q.26 What is the optimized version of the 3 Raj relation algebra expression A1 A2 F1 F2(r)))), where Al, A2 Student are sets of attributes in r with Roll. No Course Mark π (π (σ (σ e Boolean 1 Maths 80 expressions based on the attributes 1 English 70 inA1⊂A2 r ? and F1,12 ar 2 Maths 75 A1 (r)) 3 English 80 A1 (F1 ∧F2) (r)) 2 Physics 65 a) π (σ (r)) A2 (F1 ∨F2) 3 Maths 80 c) π (σ (r)) A2 (F1 ∧F2) Consider the following SQL query. b) π (σ (F1 ∨F2) [GATE-2014] SELECT S. Student_Name, sum d) π (σ (P.Marks) Q.27 Consider the following relational FROM Student S, Performance P schema: WHERE S. Roll_No =P.Roll_No employee(empId,empName,empDep) GROUP BY S.Student_Name; customer(custId,custName,salesRep The number of rows that will be Id,rating) returned by the SQL query is ______. salesRepId is a foreign key referring [GATE 2015] to empld of the employee relation. Assume that each employee makes a Q.29 SELECT operation in SQL is sale to at least one customer. equivalent to What does the following query a) the selection operation in return? relational algebra SELECT empName b) the selection operation in FROM employee E relational algebra, except that WHERE NOT EXISTS (SELECT custld SELECT in SQL retains duplicates FROM customer C c) the projection operation in WHERE C.salesRepld = E.empld relational algebra AND C.rating <>'GOOD'); d) the projection operation in a) Names of all the employees with relational algebra, except that at least one of their customers SELECT in SQL retains duplicates having a 'GOOD' rating. [GATE-2015] b) Names of all the employees with

at most one of their customers Q.30 Consider the following relation having a 'GOOD' rating. Cinema (theater, address, capacity)

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission Which of the following options will Name. and DeptName). An instance be needed at the end of the SQL of the schema EMP and a SQL query query on it are given below: SELECT P1. address EMP FROM Cinema P1 EmpId Emp Name Dept Name Such that it always finds the 1 XYA AA 2 XYB AA addresses of theaters with 3 XYC AA maximum capacity? 4 XYD AA a) WHERE P1. Capacity> = All 5 XYE AB (select P2. Capacity from Cinema 6 XYF AB P2) 7 XYG AB b) WHERE P1. Capacity> = Any 8 XYH AC (select P2. Capacity from Cinema 9 XYI AC 10 XYJ AC P2) 11 XYK AD c) WHERE P1. Capacity> = All 12 XYL AD (select max(P2. Capacity) from 13 XYM AE Cinema P2) d) WHERE P1. Capacity> = Any SELECT AVG(EC.Num) (select max (P2. Capacity) from FROM EC Cinema P2) WHERE(DepName,Num)IN (SELECTDepName, COUNT(EmpId)AS [GATE 2015] EC(DepName,Num)

Consider the following database FROM EMP Q.31 GROUP BY DepName) table named water_schemes: The output executing the SQL query Water_schemes is scheme_No district_name capacity 1 Ajmer 20 [GATE- 2017] 1 Bikaner 10 Consider the following tables & 2 Bikaner 10 Q.33 T1 T2 3 Bikaner 20 1 Churu 10 T1 T2 2 Churu 20 P Q P Q 1 Dungargarh 10 2 2 2 2 The number of tuples returned by 3 8 8 3 7 3 3 2 the following SQL query is ______. 5 8 9 7 With total(name, capacity) as 6 9 6 7 SELECT district_name, 8 5 7 2 sum(capacity) 9 8

FROM water_schemes In table T1 P is the primary key and GROUP BY district_name Q is the foreign key referencing R in With total_avg (capacity) as table T2 with on-delete cascade and SELECT avg(capacity) no update cascade. In table T2,R is FROM total the primary key and S is the foreign SELECT name key referencing P in table T1 with FROM total, total_avg on- delete set NULL and on- update WHERE total.capacity >= cascade. In order to delete record total_avg.capacity; (3,8) from table T1, the number of [GATE-2016] additional records that need to be deleted from table T1 is _____. Q.32 Consider a database that has the [GATE- 2017] relation schema EMP (Empld. Emp

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission Q. 34 Consider the following database Q.35 Consider the following two tables table named top-scorer. and four queries in SQL. top-scorer. Book (isbn, bname), Stock (isbn, Player Country Gaols copies) Klose Germany 16 Query 1: SELECT B.isbn, S.copies Ronaldo Brazil 15 G Muller Germany 14 FROM Book B INNER JOIN Stock S Fontaine France 13 ON B.isbn = S.isbn; Pele Brazil 12 Klinsmann Germany 11 Query 2: SELECT B.isbn, S.copies Kocsis Hungary 11 FROM Book B LEFT OUTER JOIN Batistuta Argentina 10 Stock S ON B.isbn = S.isbn; Cubillas Peru 10 Lato Poland 10 Lineker England 10 Query 3: SELECT B.isbn, S.copies T Muller Germany 10 FROM Book B RIGHT OUTER JOIN Rahn Germany 10 Stock S ON B.isbn = S.isbn; Consider the following SQL query: SELECT to- player FROM top scorer Query 4: SELECT B.isbn, S.copies as ta FROM Book B FULL OUTER JOIN WHERE ta. goals>ALL (SELECT tb. Stock S ON B.isbn = S.isbn; Goals FROM top scorer as tb Which one of the queries above is WHERE tb. country =’Spain’) certain to have an output that is a AND ta.goals>ANY(SELECT tc. Goals superset of the outputs of the other FROM top scorer as tc three queries? WHERE tc.country=’Germany’) a) Query 1 b) Query 2 The number of tuples returned by c) Query 3 d) Query 4 the above SQL query is ______. [GATE-2018] [GATE- 2017]

ANSWER KEY:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

(c) (a) (a) (c) (d) (d) (c) (c) (d) (d) (d) (a) (c) (b) (c) 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 (b) (b) (c) (a) (a) (a) (b) (c) (b) (c) (a) (d) 2 (d) (a) 31 32 33 34 35 2 2.6 0 7 (d)

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission EXPLANATIONS

Q.1 (c) c) Grade) {x≠5 and (x=5) are not Now, the distinct name is to be equivalent. selected, where If all are& null values x≠5 gives 1. Name of the student is selected false but not (x=5) gives true. on the basis of the grade. a) x=5 not x< (not (x=5)are 2. Instructor of the course in Korth. equivalent) 3. Courses selected on the basis of Q.2 b)(a) x=5 & (x>4 & 6) are equivalent. grade. 4. Grade should be A . The query thus, computed is Name Distinct keyword tells that it will of the students who gets A grade in give duplicate entries only once and at least one of the courses taught by if r has duplicate entries than it will Q.5 Korth.(d) not show them more than once which tells us that if answer is to be same as r then r should not have any SQL query will compute as follows duplicate entries. Options c and d 1. Selects the name from the are completely wrong but in option department b it’s also not necessary that s must 2. Selects the male employee also have no duplicate entries thus 3. Computes that The average Q.3 the(a) answer is option a. salary of male employees is

more than the average salary in 1 2 Q.6 (d) the company. The given SQL is 1, 2 n select distinct a , a ,……..a m from r r …… r There is no specific joining condition where ρ1 2 specified, so it will retrieve Cartesian All possible combination of tuples m1 2 product of the tables. Number of from r ,r , r m rows = Product of number of rows is denoted by r ×r ×…… ×r in each relation = 3 * 2 = 6 Number If P is1 a2 predicate) then to select the of columns = Sum of number of all, condition is denoted by Q.7 (c) p m columns=3+2 = 5. σ (r ×r ×…×r If we wants to select only some Update on null gives null. tuples∏ inσ the()r relation ×× r ..... ×then r composite ρ 12 m Average function ignores null values. expressiona1 ,a 2, ....,a n for above SQL is So. Average will produce Q.4 (c) Q.8 (c)(15+25+35)/3 = 25.

The relations are as given, (i) If we update in STUDENT table Students: (Roll_number, Name, dept id = NULL, it will not cause Date_of_birth) any problem to referenced table. Courses: (Course number, (ii) If we set in DEPARTMENT table Course_name, Instructor) Dept_id = NULL, it will produce Grades:(Roll_number, Course_number, inconsistency because in

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission

STUDENT table we still have the From Cars Q.9 (d) tuples containing the Dept_id= 1. Wherecolor = Red)C, Reserve R Where R.Cid = C.Cid •Number of comparisions for T3 followe d by T2 followed by Ti above query: will be correct execution sequence • 4 comparision for Red car Example:other cases some people will get selection. two times increment. 20 comparision for R.Cid = Suppose T1 followed by T2. C.Cid. If initial commission is 49500 then (ii) Select R.did he is belonging to < 50000 FROM (Select Cid So 49500*1.02 = 50490. From Cars He is eligible in second category Where color = Green)C, Reserve R then 50490*1.04=52509.6. Where R. Cid = C.Cid So he will get increment two times. • Number of comparisions for but he is eligible for only one slab of above query: Q.10 (d)commission. • 4 comparision for Green car selection. 20 comparision for R.Cid = C.Cid. Nested query ensures that for only (iii)Intersection comparision: those suppliers it returns true which {22, 22, 31, 31, 64} result of (i) supplies more than 1 item in which sub query. {22, 31, 74} result of case supplier id in inner query will (ii) sub query. 6 comparision for Q.11 (d)be repeated for that supplier. intersection by using linear search to search element. (iv)In operation of outer query: 20 The computation is as follows comparisions are required. Total 1. Select the name of the title Q.14 (b) comparision = 24+14+6+20 = 64 2. Title is selected from the book 3. Initiates a count 4. Consider book as T 5. Compute the title of five most Q.12 (a) expensive books

For color= "Red", did= {22, 22, 31, 64}

For color{22 = "Green", did = {22, 31, 74} Query 1:- Intersection of Red and Green will give = , 31} which is Karthikeyan SELECT student Q.13 (c) and Boris. FROM enrolled

WHERE student in

(SELECT Student Sub query: returns 2 rows {1, Select R.did 1}FROM Paid); FROM Cars C, Reserves R Query 2 :- WHERE R. Cid=C.Cid and SELECT student R.color=lted': FROM Paid If query Executes optimally (i) Select R.did WHERE student in FROM (Select Cid (SELECT Student

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission Query1 returns 1 row {1} Query 3 :- FROM enrolled); It selects an employee but does not compute the result as after SELECT e.student Querythe 'where2 not exists', it does not FROM enrolled e, paid have statement to produce the result. p returns It selects an employee who 2WHERE rows {1, e.student 1} = gets higher salary than2 anyone in Query 4 :- p.student; the department 5. Q.17 (b)Therefore, the query is correct. SELECT student FROM paid WHERE EXISTS If Select clause consist aggregate (SELECT * and non aggregate columns. FROM enrolled All non aggregate columns in the WHEREreturns Select clause must appear in Group 1row {1}enrolled.student = By clause. - - Final Resultpaid.student); = But in this query Group by clause consists school id instead of school Query 2 and Query 4 Q.18 (c)name. return identical row& sets for all databases, but there exit databases Q.19 (a) for which Query 1 Query 2 return Q.15 (c)different row sets on the relations. Y Query1 B 1For X = 17 ⟹ V =127; 2X 3 where A balance⟸ 3 balance ←this line computes the A Querygroup of2 customers and the balance 317 is less than dr equal to the group B. 64 6315 where A balance < B 5 balance→ this line computes the A group of customers and the balance Q.20 (a)7 127 is less 1than the group2 B. Therefore, the row produced by T query and query will be same but 1 2 S not in every case as the results of 1 Borrowe Bank Bank Manager Loan

query and2 query differ in case Manager Amount where query has the situation⟸ Ramesh Sunderajan Sunderajan 10000.00 but query has only <. Suresh Ramgopal Ramgopal 5000.00 None of the query provides the Mahesh Sunderajan Sunderajan 7000.00 correct implementation of the S ⋈ T Q.16 specification.(b) Borrowe Bank Bank Loan Employee Manager Manager Amount Ramesh Sunderajan Sunderajan 10000.00 As per given, Ramesh Sunderajan Sunderajan 7000.00 (emplidname, Ramesh Sunderajan Sunderajan 5000.00 department, salary) Mahesh Sunderajan Sunderajan 10000.00 This suggests that an employees is to be denoted using the employee Mahesh Sunderajan Sunderajan 7000.00 Id, name, department, salary Count*( S ⋈ T)=S

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission Q.21 (a) Q.25 (c)

ID 12A ∪ B Option A: does not give same result Name Age as that of given query in the case Arun 1160 where there are two records matched 15 Shreya 24 in S for a record in R. 99 Rohit Option B: does not give same result 25 Hari 40 as that of given query in the case ID 98 Rohit ID 20 where there are two same rows in A.Id > 40 ∨ C.Id < 15 12 (A∪ B) ⋈ relation R. Name Age Phone Area Option C: Gives same result as that Arun 60 10 2200 02 11 of given query. 15 Shreya 24 10 2200 02 99 Rohit 10 2200 02 Q.26 (a)Option D: Not an SQL query. 25 Hari 1140 10 2200 02 A1 A2 A1 98 Rohit 20 10 2200 02 99 Rohit 99 2100 01 i) π (π (X))= π (X), since 98 Rohit 20 99 2100 01 F1 f2 Q.22 (b) A1⊂A2 A1 A2 F1 f2 F1∧F2 ii)A1 σ (σ (X)) = σ (X) ∴π (π (σ (σ (r))))= F1∧F2 SELECT A. Id Q.27 (d)π (σ (r)) FROM A WHERE A. Age > All (SELECT B.Age FROM B WHERE B. Name = 'Arun') SELECT empName FROM employee In the table B 'Arun ' is not there, so E WHERE NOT EXISTS there query in WHERE clause (SELECT Custld returns null set. If a subquery FROM Customer C WHERE C.SalesRepld = E.empld returns zero rows, the condition AND C.rating<> evaluates as true. So, all 3 rows will be evaluated as true. where, the SQL query in the box Q.23 (c) represents all customers having other than 'good' while the complete query represents name of all employees As per SQL standard HAVING clause with all their customers having a allowed only if GROUP BY clause 'good rating'. exists. Q.28 (2)

SELECT[DISTINCT] Atributes

FROM relations The following are the two rows: [WHERE condition] Student_Name Marks [GROUP BY attributes Raj 310 [HAVING conditio]] Rohit 140 All attributes used in the GROUP BY Q.29 (d) clause must appear in the SELECT clause. Q.24 (b) ∏ in relation algebra is similar to SELECT in SQL but the only - difference is that ‘∏’ gives distinct The inner query produces last max hire date in every department located rows by eliminating duplicates but at location id 1700. The outer query Q.30 SELECT(a) does not remove duplicates simply picks all pairs of inner query. Therefore, the query produces correct result. When the ALL condition is followed by a list, the optimizer expands the

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission

Q.32 (2.6) initial condition to all elements of churu EMP the list and strings them together EmpId Emp Name Dept Name with AND operators. When 1 AA the ANY condition is followed by a 2 AA XYA list, the optimizer expands the initial 3 AA XYB AA condition to all elements of the list XYC AB and strings them together with OR 64 XYD AB Q.31 operators.(2) 5 XYE AB  XYF AC 7 XYG AC 8 XYH AC WITH Clause in SQL Used to 9 XYI 11 AD create temperory tables. 10 XYJ With total(name, capacity)as 12 AD XYK SELECT district_name,sum(capacity) 13 FROM water_schemes XYL

GROUP BY district_name XYM AE

↓ SELECT AVG(EC.Num) Tempory Table “total” FROM EC total WHERE(DepName,Num)IN name capacity (SELECTDepName, COUNT(EmpId)AS Ajmer 20 EC(DepName,Num) Bikaner 40 FROM EMP Churu 30 GROUP BY DepName) Dungargarh 10

Result of inner query With total_avg(capacity)as EC SELECT avg(capacity) AA FROM total ABDept Name 3Number ↓ AC 34 Tempory Table “total” AD 2 total_avg

capacity 1 25 13 AE = 2.6 6 SELECT name result of outer query : FROM total, total_avg Q.33 (0) EHERE total, capacity>=total_avg.capacity, ↓ Main query on temporary tables

Total X total_avg name capacity capacity Total capacity>= tital_avgcapacity Ajmer 20 25 FALSE Bikaner 40 25 TRUE Raw selected Churu 30 25 TRUE Raw selected Dungarga 10 25 FALSE rh Final Output = 2 Rows No other record need to delete T1 Name because of deletion of (3,8) record Bikaner from

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission

Q.34 (7)

Select ta. Player FROM top scorer as ta WHERE ta .Goals>ALL(SELECT tb. goals FROM top scorer as tb WHERE tb. country = ‘Spain’) AND ta.goals > ANY (SELECT tc. goals FROM top _scorer as tc WHERE tc. Country = ‘Germany’ Q.35 Number(d) of tuples in result 7. FULL OUTER JOIN In SQL the combines the results of both left and right outer joins and returns all (matched or unmatched) rows from the tables on both sides o f the join clause. So, option (d) is correct.

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission 4 RELATIONAL MODEL: RELATIONAL ALGEBRA & TUPLE CALCULUS

Q.1 Given the relations, Employee primary key is shown underlined, (name, salary, deptno), and pertaining to students in a class that Department (deptno, deptname, has at least one boy and one girl. address) What does the following relational Which of the following queries algebra expression produce?(Note la cannot be expressed using the basic is the rename operator) relational algebra operations (σ name sex=female name x, ∩,∪, - )? , π, Π (σ (student))− Π a) Department address of every n,xm(student))(sex=female⋀x=male⋀marks≤n) ⋈employee a)(student⋈names of girl students with the b) Employees whose name is the ρ highest marks same as their department name b) names of girl students with more c) The sum of all employees' marks than some boy student salaries c) names of girl students with d) All employees of a given marks not less than some boy department student [GATE – 2000] d) names of girl students with more marks than all the boy students Q.2 Which of the following relational [GATE – 2004] calculus expressions is not safe? a) {t|∃∪∈ R1 (t [A] = u [A]) ∧¬∃s ∈ Q.5 Let R1 (A , B , C) and R2 (D , E) be two R2 (t [A] = s [A])} relational schemas, where the b) {t|∀ u ∈ R1 (u [A] = “x” ⇒∃s ∈ R2 primary keys are shown underlined, (t [A] = s [A] ∧ s [A] = u [A]))} and let C be a foreign key in R1 c) {t|¬ (t ∈ R1)} referring to R2. Suppose there is no d) {t|∃u ∈ R1 (t [A] = u [A] = u [A] violation of the above referential integrity constraint in the ∧∃s ∈ R2 (t [A] = s [A])} [GATE – 2001] corresponding relational instances r1 and r2.Which one of the following relational algebra expressions would Q.3 With regard to the expressive power of the formal relational query necessarily produce an empty languages, which of the following relation? statements is true? a) ∏D (r2) – ∏c (r1) a) Relational algebra is more b) ∏c (r1) –∏D (r2) powerful c) ∏D (r2 c D r2) than relational calculus d) ∏c (r1 c D r2) b) Relational algebra has the same ⋈ [GATE – 2004] power as relational calculus ⋈ c) Relational algebra has the same Q.6 Let r be a relational instance with power as safe relational calculus schema R = (A, B, C, D). We define d) None of the above r1= A, B, C (r) and r2 = A, D (r) and r2 [GATE – 2002] = A, D(r) Let s = r1*r2 where* denotes naturalΠ join. GivenΠ that the Consider the relation Student Q.4 decompositionΠ of r into r1 and r2 is (name, sex, marks), where the

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission lossy, which one of the following is The difference between the number true? of rows output by the SQL statement a) s⊂ r b) r ∪ s = r and the number of tuples in S' is c) r⊂ s d) r * s = s a) 6 b) 4 [GATE – 2005] c) 2 d) 0 [GATE-2005] Q.7 A table 'student' with schema (roll, name, hostel, arks), and another Q.8 Which of the following relational table 'hobby' with schema (roll, query languages have the same hobbyname) contains records as expressive power? shown below: I. Relational algebra. Table Student II. Tuple relational calculus Roll Name Hostel Marks restricted to safe expressions. 1798 Manoj Rathod 7 95 III. Domain relational calculus 2154 Soumic Banerjee 5 68 restricted to safe expressions. 2369 Gumma Reddy 7 86 a) II and III only b) I and II only 2581 Pradeep Pendse 6 92 c) I and III only d) I, II and III 2643 Suhas Kulkarni 5 78 [GATE-2006] 2711 Nitin Kadam 8 72 2872 Kiran Vora 5 92 Q.9 Consider the relation enrolled 2926 Manoj Kunkalikar 5 94 (student, course) in which (student, 2959 Hemant Karkhanis7 88 course) is the primary key, and the 3125 Rajesh Doshi 5 82 relation paid (student, amount) Table Hobby where student is the primary key. Roll Hobbyname Assume no null values and no 1798 chess foreign keys or integrity constraints. 1798 music 2154 musics Assume that amounts 6000, 7000, 2369 Swimming 8000, 9000 and 10000 were each 2581 cricket chess paid by 20% of the students. 2643 hockey Consider these query plans (Plan, on 2643 volleyball left, Plan2 on right) to "list all 2711 football 2872 cricket courses taken by students who have 2926 photography paid more than x" 2959 music 3125 chess The following SQL query is executed on the above tables: Select hostel from student natural join hobby where marks > = 75 and roll between 2000 and 3000; Relations S and H with the same schema as those of these two tables respectively contain the same information as tuples. A new relation A disk seek takes 4 ms, disk data S' is obtained by the following transfer bandwidth is 300 MB/s and relational algebra operation: checking a tuple to see if amount is hostel s.roll = H.roll 75 greater than x takes10 µs Which of and roll > 2000 and roll < 3000 (S))×(H)) the following statements is correct? S’=∏ ((σ (σmarks>

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission a) Plan1 and Plana will not output c-name b-city = "Agra" b- identical row sets for all city= "Agra" bal < 0 account databases d) ∏ (σ branch ⋈ (σ b) A course may be listed more [GATE-2007] than once in the output of Plan1, ⋈depositor)) for some databases Q.12 Consider the relation employee c) For x=5000, Plan1, executes (name, sex, supervisor Name) with faster than Plan2 for all databases name as the key. Supervisor Name d) For x=9000, Plan 1 execute gives the name of the supervisor of slower than Plan 2 for all database the employee under consideration_ [GATE-2006] what does the following tunic relational calculus query produce Q.10 Consider a selection of the form {e.name | employee(e) ∩ (∀x ) (r), where r is a relation with [⇁ employee(x) U x. 1000A≤100 tuples. Assume that the supervisorName ≠ e.name U attributeσ values for A among the x.sex=”male”]} tuples are uniformly distributed in a) Names of employees with a male the interval [0, 500]. Which one of supervisor the following options is the best b) Names of employees with no estimate of the number of tuples immediate male subordinates returned by the given selection c) Names of employees with no query? immediate female subordinates a) 50 b) 100 d) Names of employees with a c) 150 d) 200 female supervisor [GATE-2007] [GATE – 2007]

Q.11 Consider the following relation Q.13 Information about a collection of schemas: students is given by the relation b-Schema = (b-name, b-city, assets) stud info (studied, name, sex). a-Schema = (a-num, b-name, bal) The relation enrol (studied, coursed) d-Schema = (c-name, a-number) Let gives which student has enrolled for branch, account and depositor be (or taken) what course(s). Assume respectively instances of the above that every course is taken by at least schemas. Assume that account and one male and at least one female depositor relations are much bigger student. What does the following than the branch relation. relational algebra expression Consider the following query: represent? c-name b- (branch ΠcourseID( Π studID() σ sex= 'female' () studInfo × city="Agra" ∧ bal<0 Which∏ o(σne of the following queries ΠcourseID () enroll− enroll) ⋈(account⋈depositor)) is the most efficient version of the a) Courses in which al l the female above query? students are enrolled c-name bal < 0 b-city = "Agra" b) Courses in which a proper subset of b)a) ∏c-name(σ b-city = (σ"Agra" female students are enrolled branch ⋈account) ⋈ depositor) bal< 0 account >a depositor)) c) Courses in which only male ∏c-name (σb-city = "Agra" branch b ⋈ - students are enrolled (σ city= "Agra" bal < 0 account d) None of the above c) ∏ (σ branch ⋈ σ depositor) [GATE – 2007] ⋈

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission Q.14 Let R and S be two relations with the who have not supplied a non- following schemas. blue part R (P, Q, R1, R2, R3) c) Find the names of all suppliers S (P, Q, S1, S2) who have supplied only blue parts Where {P, Q} is the key for both d) Find the names of all suppliers schemas. Which of the following who have not supplied only blue queries are equivalent? parts 1. Πp(R S [GATE-2009] 2. Πp(R) Πp(S) 3. Πp(Π⋈P,Q (R) ∩ΠP,Q(S)) Q.17 Assume that, in the suppliers 4. Πp(ΠP,Q⋈ (R) - (ΠP,Q(R) - ΠP,Q (S))) relation above, each supplier and a) 1 and 2 b) 1 and 3 each street within a city has a c) 1, 2 and 3 d) 1, 3 and 4 unique name, and (sname, city) [GATE – 2008] forms a candidate key. No other functional dependencies are implied Q.15 Let R and S be relational schemas other than those implied by primary such that R={a, b, c} and S= {c}. Now and candidate keys. Which one of consider the following queries on the following is TRUE about the the database: above schema?

1. πrππrXRs−()()−− Rs −−() RsSπ,s(r) Rs − a) The schema is in BCNF b) The schema is in 3NF but not in 2 t|t∈π (r) ∧∀ us ∃ v ∈ r u = v S ∧ t = v[R − S] {}Rs− ()()[] BCNF 3. ∈ ∧∀ ∃ ∈ = ∧ = − c) The schema is in 2NF but not in 3 {}t|t πRs− (r) ur() v s() u v[] S t v[R S] NF 4. Select R.a, R.b d) The schema is not in 2NF From R, S [GATE-2009] Where R.c = S.c Which of the above queries are Q.18 Suppose R1, (A, B) and R2 (C, D) are equivalent? two relation schemas. Let r1 and r2 a) 1 and 2 b) 1 and 3 be the corresponding relation c) 2 and 4 d) 3 and 4 instances. B is a foreign key that [GATE – 2009] refers to C in R2. If data in r1 and r2 satisfy referential integrity Q.16 Consider the following relational constraints, which of the following is query on the above database: always true? SELECT S.sname a) ()()rr−= FROM Suppliers S ∏∏BC12 WHERE S. sid NOT IN (SELECT C.sid b) rr−= ∏∏CB()()21 FROM Catalog C c) ()()rr= WHERE C.pid NOT IN (SELECT P.pid ∏∏BC12 FROM Parts P d) rr−≠ ∏∏BC()()12 WHERE P.color <> 'blue)) [GATE – 2012] Assume that relations corresponding to the above schema are not empty. Q.19 Consider the following relational Which one of the folly is the correct schema. interpretation of the above query? Students(rollno:integer,sname:string) a) Find the names of all suppliers Courses(courseno:integer,cname:string) who have supplied a non-blue Registration(rollno: integer, courseno: part integer, percent: real) b) Find the names of all suppliers Which of the following queries are

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission equivalent to this query in English? employee (empld, empName, “Find the distinct names of all empAge) students who score more than dependent(depld, eld, depName, 90% in the course numbered 107” depAge) I) SELECT DISTINCT S.sname Consider the following relational FROM Students as S, Registration algebra query: as R WHERE R.rollno = S . roll no empId(employee)- empId(employee AND R course no=107 AND dependent) Rpercent>90 ∏ ∏ The(empId=eId)∧(empAge≤depAge) above query evaluates to the set II) sname ) of⋈ emplds of employees whose age

(Registrationcourseno =107⋀percent>90 students)) is greater than that of III) {Π (σ Registration a) some dependent. (S.rollno= ⋈ b) all dependents. T|∃S∈Students,∃R∈ c) some of his/her dependents. me)} R.rollno∧R.courseno=1 d) all of his/her dependents. IV) 07∧R.percent>90∧T.sname=S.snaR P(|∃SP>90)}∃R >∈ Q.22 Consider two relations R1 (A, B) a)students∧ I, II, III, and IV >∈Registrat with the tuples (1, 5), (3, 7) and b)ion I, ∧ II, R and III only R2(A, C) = (1, 7), (4, 9). c) I, II, and IV only Assume that R(A,B,C) is the full d) I, III, and IV only natural outer join of R1 and R2. [GATE – 2013] Consider the following tuples of the form (A,B,C): a = (1, 5, null), b = (1, Q.20 Consider a join (relation algebra) between relations r(R) and s(S) null, 7), c=(3, null, 9), d = (4, 7, null), using the nested loop method. e=(1, 5, 7), f=(3, 7, null), g=(4,null,9). There are 3 buffers each of size Which one of the following equal to disk block size, out of which statements is correct? one buffer is reserved for a) R contains a, b, e, f, g but not c, d intermediate results. b) R contains all of a, b, c, d, e, f, g Assuming size(r(R)) < size(s(S)), the c) R contains e, f, g but not a, b join will have fewer number of disk d) R contains e but not f, g block accesses if [GATE-2015] a) relation r(R) is in the outer loop. b) relation s(S) is in the outer loop. Q.23 Consider the relations r(A,B) and c) join selection factor between s (B, C); where s.B is a primary key r(R) and s(S) is more than 0.5. and r.B is a foreign key d) join selection factor between referencing s.B. Consider the query r(R) and s(S) is less than 0.5. B<5(s)) [GATE-2014] Let LOJ denote the natural left outer- Q: r⋈(σ join operation. Assume Q.21 Consider the relational schema that r and s contain no null values. given below, where eId of the Which one of the following is NOT dependent is a foreign key referring equivalent to Q? to empld of the relation employee. Assume that every employee has at b) least one associated dependent in c)a) σB<5(r ⋈ s) the dependent relation. d) σB<5(r LOJ s) r LOJ (σB<5(s)) [GATE-2018] σB<5(r) LOJ s

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission ANSWER KEY: .

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 (c ) (c ) (c ) (d) (b) (c ) (b) (d) (c ) (d) (b) (c ) (b) (d) (c ) 16 17 18 19 20 21 22 23 (a) (b) (a) (a) (a) (d) (c ) (c)

EXPLANATIONS

Q.1 (c) CChild Column & D Parent The sum of all employees' salaries Column cannot be expressed using the given Result of Child – Parent is always algebra operations since there is no Null. command given for the sum of C(r1)– D(r2) gives empty employees out of the algebra relation. operations So π π Q.6 (c) Q.2 (c) R = (A, B, C, D)

This option contradicts itself. We r1= Π A,B,C (R)and r2= Π A,D (r) want a tuple t and t itself is in *j and S = r1*r2 we want other tuples than t by using The tuples in s are more than that of negation so it's not safe. r. Also, s consists of all the tuples of r along with other tuples. Q.3 (c) Therefore, the most appropriate This is a rule of that relational algebra has same power as safe relational calculus. Q.7 (b)relation is r ⊂ s. SQL query will return the following Q.4 (d) output. Going with the given query, it means Roll Hostel the following Name of the female 2369 7 student - name of the females who 2581 6 scored less than boys. 2643 5 Therefore, it computes the name of 2643 5 Duplicate Row is present in the girl student with more marks Hobby table than all the boy students. 2872 5 2926 5 Q.5 (b) 2959 7 R1 (A, B, C) Total 7 rows are selected R2 (D,E) In Relation Algebra, only distinct Given that, A is primary key of R1 values of hostels are selected i.e. and D is primary key of R2 and C is a 5,6,7. foreign key in R1, referring to Therefore SQL row count RA row primary key of R2. count = 7- 3 = 4. Q.8 (d)

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission Given three relational query sex=”female”(studinfo)) tells that languages have same expressive students are females. power. (σcourseld(Enroll)) Gives the Id of the course in which to enroll. Q.9 (c) (Π studid) tells regarding a proper Given that left hand side is plan and 1 subset of females that are enrolled. right hand side is plan2. Finally,𝚷𝚷 Plan1 courseld tells Course in which a 1.Select records form paid proper subset of female students are 2.Joins them enrolled.Π

Plan2 1.Joins records from paid Q.14 (d) 2.Records are checked Execute the given queries on the The seek time of disk is 4 ms and given tables. [key= PQ] data transfer rate is 300 MB/s. Options I, III, and IV are identical. So, if x = 5000. Although the output R remains the same but the plan1 P Q executes faster than plan2 for all 1 A databases. 2 B Q.10 (d) 3 D Number of tuples in relation r = 1000 S Each value of A is appeared twice, P Q 1 A because uniformly distributed in [0, 2 C (r) returns 200 tuples. 4 D A≤100 Q.11 (b)500] σ P As b is very small compared to a and 1 d which is also taken in account. P 1 b-city="Agra” branch which already filter city as agra making it small, 2

andσ before bal<0 I) (R S) depositor filter and give selected P II) (R) (S) returns that σ accountll give ⋈ P P Π ⋈ (S)) same result and better one. P P,Q P,Q Only II)Π (R) –⋈ Π (R) - tables so ⋈ between them wi P P,Q P,Q P,Q III) (S)))Π (Π returns(R) ˄ Π

Q.12 (c) IV) Π (Π (Π Π We are given with the below

relational calculus: Q.15 (c) This is very clear from the options (e.name | employee (e) } itself that the option 2 and option 4 are equivalent as option 2 is

technical representation of code (e.name(∀X)[⇁employee(X)⋁X.supervisorN | employee (e) } gives the given in option 4. Therefore, ame≠X.sex=”male”]name of the employee tells that {t | t∈π (r) ∈ s( ∃ v ∈ r(u = v[s] ∧ t = v[R − S]))} employee does not have any female RS− subordinate. = Select R.a, R.b From R, S Q.13 (b) = Where R.c = S.c

Q.16 (a)

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission Supplier sells other than blue part it 4. Domain Calculus Domain can be red or green or both. Calculus is equivalent to relational algebra and provides Q.17 (b) distinct value for the query, true. Suppliers (Sid, Sname, City, Street) Hence, all queries are equivalent to 1. Each supplier and each street this query in English. (a) I, II, III and within a city has a unique name IV. Sid Street City Sname 2. (Sname, city) forms candidate Q.20 (a) key so that (Sname city) -+ Sid Join will have fewer number of disk Street 3. Sid primary key so that block accesses if outer loop has Sid -> Sname City Street Each FD smaller relation (r(R)). of above satisfy BCNF. (a) RI (A, B) R2 (C, D) B is a foreign Q.21 (d) key and referring to C & C is empId empId(employee candidate key So, IIB(ri) -11c(r2) dependent) π (employee)−π = E E.g. B2 Where,(empId=eId)⋀(empAge≤depAge)

i)⋈ empId Q.18 (a) depAge)dependent) Suppose, there are two relation (empId=eId)⋀(empAge≤ Meansπ (employee⋈ schemas. All employees whose age is less than R1 (A, B) and R2 (C, D). or equal to that of all of his r1 and r2 are Two relation instances dependents. of R1 and R2 respectively. : - B is a foreign key that refers to C in ii) empId empId(employe R2. B  Child Column & C  Parent π (employee)−π (empId=eId)⋀(empAgedependent). Column e⋈ Means≤depAge) Child Column – Parent Column is All employees whose age is greater always empty. than that of all of his dependents. B(r1)- C(r2) gives empty relation.

Q.22 (c) π π Q.19 (a) “Find the distinct names of all R A B R A C students who score more than 90% 1 2 1 5 1 7 in the course numbered 107”. 3 7 4 9 1. SQL Query Condition would R=R R give all sname having score > 90 1 2 R contains e, f, g but not a, b. and attending course no. 107

and DISTINCT S.sname will give distinct student names, true R A B C 2. Relational Algebra gives 1 5 7 projection of all students 3 7 Null meeting the condition and 4 Null 9 → gives DISTINCT value, true → 3. Tuple Calculus Gives DISTINCT Q.23 (c) → student name having score > 90 Consider the following relations r(A, and course No is 107, true B) and S(B, C), where S.B is a primary key and r.B is a foreign key

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission referencing S.B Consider the following tables without NULL values.

Q: r B<5(S)) B<5(r LOJ S) is B<5(S) is ⨝(σ The result of σ The result of σ

The result of r B<5(S) is Option (C): Th B<5(S) is ⨝(σ e result of σ

B<5(S)) Option (A): The result of r S is Now, the result of r LOJ(σ ⨝

Option (D): B<5(r S) is The B<5(r) is Now, B<5(r) LOJ S is

The result of σ ⨝ σ σ

Option (B): The result of r LOJ S is Therefore, from the output of above four options, the results of options (a), (b) and (d) are equivalent to Q.

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission 5 TRANSACTIONS & CONCURRENCY CONTROL Q.1 Which of the following scenarios a) Page may lead to an irrecoverable error b) Table in a database system? c) Row a) A transaction writes a data item d) Page, table and row level locking after it is read by an allow the same degree of uncommitted transaction concurrency b) A transaction reads a data item [GATE-2004] after it is read by an uncommitted transaction Q.4 Consider the following schedule S of c) A transaction reads a data item transactions Tl and T2: after it is written by an T1 T2 uncommitted transaction Read(A) d) A transaction reads a data item A = A-10 after it is written by an Read(A) Temp = 0.2 * A uncommitted transaction Write(A) [GATE – 2003] Read(B) Write(A) Q.2 Consider three data items D1, D2 and Read(B) D3 and the following execution B=B+10 B= B+ Temp schedule of transactions T1, T2 and Write(B) Write(B) T3. In the diagram, R (D) and W (D) denote the actions reading and Which of the following is TRUE writing the data item D respectively. about the schedule S ? a) S is serializable only as T1, T2 b) S is serializable only as T2, T1 c) S is serializable both as T1, T2 and T2, T1 d) S is not serializable either as Ti or as T2 [GATE-2004] Q.5 Amongst the ACID properties of a Which of the following statements is transaction, the 'Durability' property requires that the changes made to correct? the database by a successful a) The schedule is serializable as transaction persist T ; T ; T 2 3 1 a) Except in case of an Operating b) The schedule is serializable as System crash T ; T ; T 2 1 3 b) Except in case of a Disk crash c) The schedule is serializable as c) Except in case of a power failure T ; T ; T 3 2 1 d) Always, even if there is a failure d) The schedule is not serializable of any kind [GATE – 2003] [GATE-2005] Q.3 Which level of locking provides the Q.6 Consider the following log sequence highest degree of concurrency in a of two transactions on a bank relational database?

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission account, with initial balance 12000, T1: T2: that transfer 2000 to a mortgage read(A); read(B); payment and then apply a 5 % read(B); read(A); If A= 0 thenB←B+1; If B 0 then A 4.- A←1; interest write(B); write(A); 1. T1 start Which of the following schemes, 2. T1 B old = 1200 new = 10000 using shared and exclusive locks, 3. T1 M old = 0 new = 2000 satisfy the requirements for strict 4. T1 Commit two phase locking for the above 5. T2 start transactions? 6. T2 B old = 10000 new = 10500 a) S1 : S2 : 7. T2 Commit lock S(A); lock S(B); Suppose the database system crashes read (A); read (B); just before tog record 7 is written. lock S(B); lock S(A); When the system is started, which read (B); read (A); one statement is true of the if A = 0 if B ≠ 0 recovery procedure? then B ←B+1; then A ←A-1; a) We must redo log record 6 to set write (B); write (A); )9 to 10500 commit; commit; b) We must undo log record 6 to set unlock (A); unlock (B); 13 to 10000 and then redo log unlock (B); unlock (A); records 2 and 3 b) S1 : S2 : c) We need not redo log records 2 lock X(A); lock X(B); and 3 because transaction T1 has read (A); read (B); committed lock X(B); lock X(A); d) We can apply redo and undo read (B); read (A); operations in arbitrary order if A = 0 if B ≠ 0 because they are idempotent then B← B+1; then A ← A-1; [GATE – 2006] write (B); write (A); unlock (A); unlock (A); Q.7 Consider the following schedules commit; commit; involving two transactions. Which unlock (B); unlock (A); one of the following statements is c) S1 : S2: true? lock S(A); lock S(B); S1:r1(X);r1(Y); r2(X); r2(Y); w2(Y); read (A); read (B); w1(X) lock X(B); lock X(A); S2:r1(X);r2(X);r2(Y); w2(Y); r1(Y);; read (B); read (A); w1(X) if A = 0 if B ≠ 0 a) Both S1 and S2 are conflict then B← B+1; then A ← A- 1; serializable write (B); write (A); b) S1 is conflict serializable and S2 unlock (A); unlock (A); is not conflict serializable commit; commit; c) S1 is not conflict serializable and unlock (B); unlock (A); S2 is conflict serializable d) Both Si and S2 are not conflict d) S1 : S2 : serializable lock S(A); lock S(B); [GATE – 2007] read (A); read (B); lock X(B); lock X(A); Q.8 Consider the following two read (B); read (A); transactions: T1 and T2. if A = 0 if B ≠ 0

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission then B ←B+1; then A ←A-1; Q.11 Consider the following schedules for write (B); write (A); transactions T1, T2 and T3 unlock (A); unlock (A); T1 T2 T3 unlock (B); unlock (B); Read (X) commit; commit; Read (Y) [GATE-2007] Read (Y) Write (Y) Q.9 Consider the following three Write (X) schedules of transactions T1, T2 and Write (X) T3. [Notation: In the following NYO Read (X) represents the action Y (R for read, Write (X) W for write) performed by transaction N on object 0]. Which one of the schedules below is S1:2RA 2WA 3RC 2WB 3WA 3WC the correct serialization of the 1RA 1RB 1WA 1WB above? S2: 3RC 2RA 2WA 2WB 3WA 1RA a) T1→T3 → T2 b) T2 →T1 →T3 1RB 1WA 1WB 3WC c) T2 →T3 →T1 d) T3 →T1 →T2 S3: 2RA 3RC 3WA 2WA 2WB 3WC [GATE – 2010] 1RA 1RB 1WA 1WB Which of the following statements is Q.12 Which of time following TRUE? concurrency control protocols a) S1, S2 and S3 are all conflict ensure both conflict serializability equivalent to each other No two and freedom from deadlock? of S1, 1. 2-phase locking b) S2 and S3 are conflict equivalent 2. Time-stamp ordering to each other a) 1 only b) 2 only c) S2 is conflict equivalent to S3, c) Both 1 and 2 d) neither 1 nor 2 but not to S1 [GATE – 2010] d) S1 is conflict equivalent to S2, but not to S3 Q.13 Consider the following transactions [GATE-2008] with data items P and Q initialized to zero: Q.10 Consider two transactions T1, and T1 T2 T2, and four schedules S1, S2, S3, S4 of read (P): read (Q): T1 and T2 as given below: read (Q) read (P) T1: R1[x] W1 [x] W1[y] if P=0 then Q: Q+1 if Q=0 then P: P+1 write (Q) write (P) T2: R2[x] R2 [y] W2 [y] Any non-serial interleaving of T1 S1: R1[x] R2 [x] R2 [y] W1 [x] W1[y] and T2 for concurrent execution W2 [y] leads to S2: R1[x] R2 [x] R2 [y] W1 [x] W2 [y] a) a serializable schedule W1[y] b) a schedule that is not conflict S3: R1[x] W1 [x]] R2 [x] W1[y] R2 [y] serializable W2 [y] c) a conflict serializable schedule S4: R2[x] R2 [y] R1[x] W1 [x] W1[y] d) a schedule for which a W2 [y] Which of the above schedules are precedence graph cannot be conflict-serializable? drawn [GATE – 2012] a) S1 and S2 b) S2 and S3

c) S3 only d) S4 only [GATE – 2009] Q.14 An index is clustered, if

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission a) it is on a set of fields that form a T1: rl (X); H. (Z); wl (X); wl(Z) candidate key. T2: r2 (Y); r2 (Z); w2 (Z) b) it is on a set of fields that include T3: r3 (Y); r3 (.X); w3 (Y) the primary key. S1 : rl (X); r3 (Y); r3 (X); r2 (Y); r2 c) the data record of the file are (Z); w3(Y); w2 (Z); rl(Z); wl(X); organized in the same order as wl(Z) the date entries of the index S2 : r1 (X); r3 (Y); r2 (Y); r3 (X); d) the data records of the file are ri(Z); r2(2); w3 (17); wl (X); w2 organized not in the same order (2); wl(Z) as the data entries of the index. Which one of the following [GATE-2013] statements about the schedules is TRUE? Q.15 Consider the following four schedules a) Only S1 is conflict-serializable. due to three transactions (indicated b) Only S2 is conflict-serializable. by the subscript) using read and c) Both Si and S2 are conflict- write on a data item x, denoted by serializable. r(x) and w(x) respectively. Which d) Neither S1 nor S2 is conflict- one of them is conflict serializable? serializable. a) r1(x); r2(x); w1(x); r3(x); w2(x) [GATE-2014] b) r2(x); r1(x); w2(x); r3(x); w1(x) c) r3(x); r2(x); r1(x); w2(x); w1(x) Q.18 Consider the following transaction d) r2(x); w2(x); r3(x); r1(x); w1(x) involving two bank account x and [GATE-2014] y.read (x) ; x : = x – 50; Q.16 Consider the following schedule S of write (x) ; transactions T1, T2, T3 and T4: read (y); T1 T2 T3 T4 Reads(X) y : = y + 50 ; Writes(Y write (y); ) Writes(X The constraint that the sum of the Writes(X ) Commit accounts x and y should remain ) Commit constant is that of Reads(X Writes(Y ) a) Atomicity b) Consistency ) Reads(Y c) Isolation d) Durability Reads(Z) ) [GATE 2015] Commit Commit Q.19 Consider a simple check pointing Which one of the following protocol and the following set of statements is CORRECT? operations in the log. (Start, T4); a) S is conflict-serializable but not (write, T4, y, 2, 3); (Start, T1); recoverable (commit, T4); (Write, T1, z, 5, 7); b) S is not conflict-serializable but (checkpoint); (Start, T2); (write, T2, is recoverable . x, 1, 9); (commit, T2); (start, T3), c) S is both conflict-serializable and (write, T3, z, 7, 2); recoverable If a crash happens now and the d) S is neither conflict-serializable system tries to recover using both nor is it recoverable undo and redo operations, what are [GATE-2014] the contents of the undo lists and

Q.17 Consider the transactions T1, T2, the redo list? and T3 and the schedules S1 and S2 a) Undo T3,T1; Redo T2 given below. b) Undo T3,T1; Redo T2,T4

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission c) Undo: none; redo :T2,T4,T3,T1 transaction T accesses (for read or d) Undo T3,T1; T4; Redo :T2 write operations), a certain set of [GATE 2015] objects {O1,...... ,Ok}. This is done in the following manner: Q.20 Consider the following partial Step: 1  “T” acquires exclusive Schedule S involving two locks to O1,...., Ok in increasing transactions T1 and T2. Only the order of their addresses. read and write operations have Step: 2  The required operations been shown. The read operation on are performed. data item P is denoted by read (P) Step: 3  All locks are released. and the write operation on data This protocol will item P is denoted by write (P). a) Guarantee Serializability and Time Transaction ID deadlock-freedom Instance b) Guarantee neither Serializability T1 T2 nor deadlock-freedom 1 Read(A) 2 Write(A) c) Guarantee Serializability but not 3 Read(C) deadlock-freedom 4 Write(C) d) Guarantee deadlock-freedom but 5 Read(B) not Serializability 6 Write(B) [GATE 2016] 7 Read(A) 8 Commit Q.23 Suppose a database schedule S 9 Read(B) Suppose that the transaction T1 fails involves transactions T1, ..., Tn. immediately after time instance 9. Construct the precedence graph of S Which one of the following with vertices representing the statements is correct? transactions and edges representing a) T2 must be aborted and then the conflicts. If S is Serializable, which one of the following orderings both T1 and T2 must be re- started to ensure transaction of the vertices of the precedence atomicity graph is guaranteed to yield a serial b) Schedule S is non-recoverable schedule? a) Topological order and cannot ensure transaction atomicity b) Depth-first order c) Only T2 must be aborted and c) Breadth-first order then re-started to ensure d) Ascending order of transaction indices transaction atomicity [GATE 2016] d) Schedule S is recoverable and

can ensure atomicity and Q.24 Consider the following database nothing else needs to be done schedule with two transactions T1 [GATE 2015] and T2. Q.21 Which one of the following is NOT a S = r2(X); r1(X); r2(Y); w1(X); r1(Y); part of the ACID properties of w2(X); a1; a2 database transactions? Where “ri(Z)” denotes a read a) Atomicity b) Consistency operation by transaction “Ti” on a c) Isolation d) Deadlock-freedom variable Z, “wi(Z)” denotes a write [GATE 2016] operation by “Ti” on a variable Z and “ai” denotes an abort by transaction Q.22 Consider the following two phase Ti. Which one of the following locking protocol. Suppose a

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission {t | u  EMP(t[EmpName] u[EmpName] statements about the above I schedule is TRUE? v  DEPT(t[DeptId] v[DeptId]))} a) S is non-recoverable {t | u  EMP(t[EmpName] u[EmpName] II. b) S is recoverable, but has a v  DEPT(t[DeptId] v[DeptId]))} cascading abort III. {t | u  EMP(t[EmpName] u[EmpName] c) S does not have a cascading v  DEPT(t[DeptId] v[DeptId]))} abort Which of the above queries are safe? d) S is strict. a) I and II only b) I and III only [GATE 2016] c) II and III only d) I, II and III [GATE 2017] Q.25 Consider a database that has the relation schema CR (Schema CR Q.27 In a database system, unique (Student name, Course Name). An timestamps are assigned to each instance of the schema CR is as transaction using Lamport’s logical given below: clock. Let TS( T ) and TS( ) be the 1 CR timestamps of transactions and Student Name Course Name respectively. Besides holds a SA CA SA CB lock on the resource R and has SA CC requested a conflicting lock on the SB CB SB CC same resource R. The following SC CA algorithm is used to prevent SC CB deadlocks in the database system SC CC assuming that a killed transaction is SD CA restarted with the same timestamp. SD CB If TS( ) < TS( ) then SD CC SD CD is killed SE CD SE CA else waits SE CB Assume an transaction that is not SF CA killed terminates eventually. Which SF CB of the following is TRUE about the SF CC database system that uses the above The following query is mad on the algorithm to prevent deadlocks? database. a) The database system is both T1  CourseName  StudentName 'SA' (CR) deadlock- free and starvation –

T21 CR T free b) The database system is deadlock The number of rows in T is ___. 2 free, but not starvation – free [GATE 2017] c) The database system is starvation free, but not Q.26 Consider a database that has the deadlock- free relation schemas EMP (EmpId, d) The database system is neither EmpName, Deptid) and DEPT (Dept deadlock –free nor starvation – name, Deptid). Note that the Deptid free. can be permitted to be NULL in the [GATE 2017] relation EMP. Consider the following Q.28 Two transactions and are queries on the database expressed in tuple relational calculus. given as

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission T1 :r(X)w 1 1 (X)r(Y)w 1 1 (Y) transaction on a variable V. The

T2 :r 2 (Y)w 2 (Y)r 2 (Z)w 2 (Z) total number of conflict serializable schedules that can be formed by T1 Where ri (V) denotes a read operation andT2 is ______. by transaction Ti on a variable V and [GATE 2017] w (V) denotes a write operation by i

ANSWER KEY:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 (d ) (d) (d) (d) (c ) (c ) (c ) (c ) (c ) (b) (a) (b) (b) (c ) (d) 16 17 18 19 20 21 22 23 24 25 26 27 28 (c ) (a) (b) (a) (b) (d) (a) (a) (c ) 4 (d) (a) 54

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission EXPLANATIONS

Q.1 (d) We need not redo log records 2 and A transaction reads a data item after 3 because transaction T1 has it is written by an uncommitted committed. transaction. As the errors cannot recover in this situation. Q.7 (c) Let’s construct the S1 and S2 with the Q.2 (d) time to check the serializable conflict. The given schedule is neither conflict serializable [cycle formed between T1 & T2]nor view serializable [for D1 order is T1→T2, and for D2 order is T2→T1], hence it S → No serializable conflict is not serializable because as 1 S → Serializable conflict inW (x) operations are not given we can’t 2 1 verify for result equivalence. Q.8 (c) Requirement to follow Strict 2PL Q.3 (d) 1. Exclusive locks should be A transaction reads a data item after released after the commit . it is written then we can't recover 2. No Locking can be done after the the errors in this situation by an first Unlock and vice versa. uncommitted transaction. In 2PL, deadlock may occur but it may be that it doesn't occur at Q.4 (d) all. Consider that in option (c) if We have sequence W2(D2) both execute in serial order →W1(D1) without concurrency then that is Which means T2→T1 whereas we perfectly valid and YES it follows also have Wl(D1)→R2(D1) which Strict 2PL. means Ti T2. Both are not possible. Therefore, schedule is not Q.9 (c) serializable. (i) Schedule S1: 2RA, 2WA, 3RC, 2WB, 3WA.. 3WC, 1RA, 1RB, Q.5 (c) 1WA, 1WB. Row level locking provides more T1 T2 T3 concurrency. Because different R(A) transactions can access different W(A) rows in a table/page at same time. R(C) W(B) W(A) Q.6 (c) W(C) As it is given that the transaction is R(A) already committed, the changes are R(B) already made. Now, since the W(A) changes are made, they are W(B) permanent so we do need to restore S1 is conflict serializable. them as the failure has no effect on T2 →T3 → T1 the transaction.

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission (ii) Schedule S2: 3RC, 2RA, 2WA, Let us construct the schedule and 2WB, 3WA_ 1RA, 1RB, 1WA, transition diagram to determine the 1WB, 3WC. conflict: Schedule S2 T1 T2 T3 R(C) R(A) W(A) W(B) W(A) R(A) R(B) Dependency graph have W(A) W(B) no cycles. W(C) Schedule S3 S2 is conflict serializable T2→T3→T1 S1 is conflict equivalent to S2. iii) Schedule S3: 2RA, 3RC, 3WA, 2WA, 3WB, 3WC,1RA, 1RB,1WA, 1WB. Here, we can see that 5, and S are T1 T2 T3 4 not conflict serializable but S and 5 R(A) 2 3 are conflict serializable. R(C) W(A) Q.11 (a) W(A) The solution can be obtained by W(B) checking with all the available W(C) options. The correct serialization is R(A) TTT. R(B) 1 3 2 W(A) This will result in same result as in W(B) the given schedule and will not S3 is not conflict serializable. conflict in read write operation of same data items.

Q.12 (b) Therefore S1 and S2 are conflict Time stamp ordering ensures both cycle equivalent schedules but S3 conflict serializability and freedom is not equivalent to Si and S3. from deadlock as timestamp-based concurrency control is a non-lock Q.10 (b) concurrency control method. The method is employed in relational databases to safely handle transactions. It uses the timestamps for the same.

Q.13 (b)

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission Precedence graph for the schedule ∴ Conflict serializable and it is also says that it is not the conflict recoverable. serializable schedule so option (c) is not correct. Q.17 (a) Also option (d) is eliminated S1: r1(X ); r3(Y); r3(X ); r2(Y); r2(Z); because graph can be drawn but it w3(Y); w2(Z); rl(Z); w1(X); w1(Z) has cycle. Above schedule is not even view serializable schedule (it fails the condition of view serializable schedule). No cycle⇒ S1 is conflict serializable. So, above schedule is not S2: r1(X ); r3(Y); r2(Y); r3(X ); rl(Z); serializable schedule. r2(Z); w3(1); wl(X); w2(Z); w1(2)

Q.14 (c) Clustered index sort the data in the table based on their key values of Cycle S2 is not conflict serializable. the column on which clustered Q.18 (b) index is created. So option (c) is Consistency in database systems correct. refers to the requirement that any

given database transaction must only Q.15 (d) change affected data in allowed (a) r (x); r (x); w (x); r (x); w (x) 1 2 1 3 2 ways, that is sum of x and y must not change.

Q.19 (a) Contains cycle; Not conflict Since T1 and T3 are not committed serializable yet, they must be undone. The (b) r (x); r (x); w (x); r (x); w (x) 2 1 2 3 1 transaction T2 must be redone because it is after the latest checkpoint. Contains cycle; Not conflict serializable Q.20 (b) T2 reads value of 'A' which is (c) r3(x); r2(x); r1(x); w2(x); w1(x) written by T1 and T2 is committed before T1.

Contains cycle; Not conflict Q.21 (d) serializable Deadlock-freedom is not an ACID (d) r2(x); w2(x); r3(x); r1(x); w1(x) property of Transaction. ACID Properties of transaction are A  Atomicity C  Consistency Not contains cycle; conflict serializable. I  Isolation D  Durability Q.16 (c) Q.22 (a) Two Phase Locking Protocol  Always guarantee Serializability.

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission As Locks are requested in increasing T1 result : order  No cycle will be formed, Course Name hence it is a deadlock free protocol. CA The given technique guarantees CB Serializability & Deadlock Freedom CC

T result: CR T ⇒ student name Q.23 (a) 2 1 Arranging vertices in Topological for which every course name of CA, order guarantees the precedence CB,CC is graph yield serial schedule because, SA the arrangement of Topological SC order confirms that there is no cycle SD in the graph [Since Topological SF ordering is possible only for 4 tuples in result Directed Acyclic graph]. When there is no cycle, the corresponding Q26 (d) schedule is Serializable and the I. ordering of vertices gives the {t | u  EMP(t[EmpName] u[EmpName] resultant serial schedule [Linear v  DEPT(t[DeptId] v[DeptId]))} arrangement of vertices based on Results empname who does not paranthesis theorem]. belongs to any departments Consider the below Topological (safe query). ordering of vertices [transactions] II. which says that the resulting serial {t | u  EMP(t[EmpName] u[EmpName] schedule is T1T2T3 v  DEPT(t[DeptId] v[DeptId]))} Results empname who does not belongs to some departments (safe query). Q.24 (c) II The given schedule does not have {t | u  EMP(t[EmpName] u[EmpName] cascading aborts, since all Read v  DEPT(t[DeptId] v[DeptId]))} Operations are committed Read Results empname who belongs only. To verify for recoverability and to some departments (safe cascading aborts, we have to focus query). on WRITE-READ sequencing, we ∴ All are safe queries. have to search for Dirty Read operation by any transaction. Q.27 (a) Given Schedule  Has No Dirty holds lock on resource R,  Reads Schedule has no cascading requires conflict lock on same aborts. T1 T2 resource R R2(X) R1(X) R2(Y) W1(X) Wait for graph R1(Y) W2(X) If TS( ) < TS( ) Abort The killed [restart with same TS Abort value] else waits. Avoids both

deadlock is starvation Q.25 (4)

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission

Q.28 (54)

T1 :r(X)w 1 1 (X)r(Y)w 1 1 (Y)

T2 :r 2 (Y)w 2 (Y)r 2 (Z)w 2 (Z) (i) Number of conflict serializable on T T :1 12

r(X)w1 1 (X)r(Y)w 1 1 (Y)r 2 (Y)w 2 (Y)r 2 (Z)w 2 (Z)

(ii) Number of conflict seralizable o

T21 T :53

S:r2 (Y)w 2 (Y)r(Y)w 1 1 (Y)

r11 (X)w (X) must be before r1 (Y)

So that r22 (Y)w (Y)  r11 (Y)w (Y)  can place. 4 C2  6ways

1. r2 (Y)w 2 (Y)r(X)w 1 1 (X)r(Y)w 1 1 (Y) 6 r22 (Z)w (Z) can place i C2  15ways

2. r2 (Y)r(X)w 1 1 (X)w 2 (Y)r(Y)w 1 1 (Y) can place

3. r2 (Y)r(X)w 1 2 (Y)w 1 (X)r(Y)w 1 1 (Y) 5 can place i C2  10ways

4. r(X)w1 1 (X)r 2 (Y)w 2 (Y)r(Y)w 1 1 (Y) can place in

5. r(X)r1 2 (Y)w 2 (Y)w 1 (X)r(Y)w 1 1 (Y) can place i

6. r(X)r1 2 (Y)w 1 (X)w 2 (Y)r(Y)w 1 1 (Y) can place in . Total conflict serializable of T and 1

T2 =53+1=54 ways

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission 6 FILE STRUCTURES

+ Q.1 B trees are preferred to binary 512bytes; each data pointer PD is 8 trees in databases because bytes long and each block pointer P a) Disk capacities are greater than B is 5 bytes long .In order for each B- memory capacities tree node to fit in a single disk block, b) Disk access is much slower than the maximum value of p is memory access a) 20 b) 22 c) Disk data transfer rates are c) 23 d) 32 much less than memory data [GATE-2004] transfer rates d) Disks are more reliable than Q.5 Which one of the following is a key memory factor for preferring B+ trees to [GATE – 2000] binary search trees for indexing database relations? Q.2 A B+ tree index is to be built on the a) Database relations have a large Name attribute of the relation number of records STUDENT. Assume that all student b) Database relations are sorted on names are of length 8 byte, disk the primary key blocks are of size .512- byte and c) B+ trees require less memory index pointers are of size 4 byte. than binary search trees Given this scenario, what would be d) Data transfer from disks is in the best choice of the degree (i.e, the blocks number of pointers per node) of the [GATE – 2005] B+ tree? a) 16 b) 42 Q.6 A.B Tree used as an index for a large c) 43 d) 44 database table has four levels [GATE – 2002] including the root node. If a new key is inserted in this index, then the Q.3 The order of an internal node in a B+ maximum number of nodes that tree index is the maximum number could be newly created in a the of children it can have. Suppose that process are a child pointer takes 6 byte, the a) 5 b) 4 search field value takes 14 byte, and c) 3 d) 2 the block size is 512 byte. What is [GATE-2004] the order of the internal node? Linked Answer Questions Q.7& Q.8 a) 24 b) 25 A database table T1 has 2000 records and c) 26 d) 27 occupies 80 disk blocks. Another table T2 [GATE – 2004] has 400 records and occupies20 disk blocks. These two tables have to be joined Q.4 Consider a table T in a relational as per a specified join condition that needs database with a key field K. A B – to be evaluated for every pair of records tree of order p is used as an access from these two tables. The memory buffer structure an K where p denotes the space available can hold exactly one block maximum number of tree pointers of records for T1 and one block of records in a B-tree index node. Assume that for T2 simultaneously at any point in time. K is 10 bytes long; disk block sixe is No index is available on either table.

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission Q.7 If Nested – loop join algorithm is employed to perform the join, with the most appropriate choice of table to be used in outer loop, the number of block accesses required for reading the data are a) 800000 b) 40080 c) 32020 d) 100 Q.11 Keys K15 and then K25 are inserted [GATE-2005] into this tree in that order. Exactly how many of the following nodes Q.8 If, instead of Nested – loop join, (disregarding the links) will be Block nested – loop join is used, present in the tree after the two again with the most appropriate insertions? choice of table in the outer loop, the reduction in number of block accesses required for reading the a)1 b)2 data will be c)3 d)4 a) 0 b) 3040 [GATE-2007] c) 38400 d) 798400 [GATE-2005] Q.12 Now the key K50 is deleted from the B+ tree resulting after the two Q.9 In a database file structure , the insertions made earlier. Consider search key field is 9 bytes long, the following statements about the block size is 512 bytes, a record B+ tree resulting after this deletion. pointer is 7 bytes and a block i) The height of the tree remains pointer is 6 bytes .The largest the same. possible order of a non- leaf node in ii) The node k20 (disregarding the a B + tree implementing this file links) is present in the tree. structure is iii) The root node remains a) 23 b)24 unchanged (disregarding the c) 34 d) 44 links)Which one of the following [GATE-2005] options is true? a) Statements (i)and (ii) are true Q.10 The order of a leaf node in a B* tree b) Statements (ii) and (iii) are true is the maximum number of (value, c) Statements (iii) and (i) are true data record pointer) pairs it can d) All the statements are false hold. Given that the block size is 1 [GATE-2007] Kbyte, data record pointer is 7 byte long, the value field is 9 byte long Q.13 Consider a file of 16384 records. and a block pointer is 6 Byte long, Each record is 32 bytes long and its what is the order of the leaf node? key field is of size 6 bytes. The file is a) 63 b) 64 ordered on a non-key field, and the c) 67 d) 68 file organization is unspanned. The [GATE – 2007] file is stored in a file system with block size 1024 bytes, and the size Directions for question Q.11to Q.12: of a block pointer is 10 bytes. If the Consider the B+ tree in the adjoining figure, secondary index is built on the key Where each node has at most two keys and field of the file, and multi-level index three links. scheme is used to store the

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission secondary index, the number of Q.18 With reference to the B+ tree index first-level and second-level blocks in of order 1 shown below, the the multi-level index are minimum number of nodes respectively? (including the Root node) that must a) 8 and 0 b) 128 and 6 be fetched in order to satisfy the c) 256 and 4 d) 512 and 5 following query: “Get all records [GATE-2008] with a search key greater than or equal to 7 and less than 15” is ______Q.14 A clustering index is defined on the fields which are of type a) non-key and ordering, b) non-key and non-ordering c) Key and ordering d) key and non-ordering [GATE – 2008] [GATE 2015] Q.15 The following key values are inserted into a B+ tree in which Q.19 Consider a B+ tree in which the order of the internal nodes is 3, and search is 12 bytes long, block size is that of the leaf nodes is 2, in the 1024 bytes, record pointer is 10 sequence given below. The order of bytes long and block pointer is 8 internal nodes is the maximum bytes long. The maximum number of number of tree pointers in each keys that can be accommodated in node, and the order of leaf nodes is each non-leaf node of the tree is ____ the maximum number of data items [GATE-2015] that can be stored in it The B+tree is initially empty. 10, 3, 6,8,4,2, 1 The Q.20 B+ Trees are considered BALANCED maximum number of times leaf because nodes would get split up as a result a) the lengths of the paths from the of these insertions is root to all leaf nodes are all a) 2 b) 3 equal. c) 4 d) 5 b) the lengths of the paths from the [GATE – 2009] root to all leaf nodes differ from each other by at most 1. Q.16 Consider a B+ tree in which the c) the number of children of any maximum number of keys in a node two non-leaf sibling nodes differ is 5. What is the minimum number by at most1. of keys in any non-root node? d) the number of records in any a) 1 b) 2 two leaf nodes differ by at most1 c) 3 d) 4 [GATE-2016] [GATE – 2010] + Q.21 In a B tree, if the search-key value Q.17 A file is organized so that the is 8 bytes long, the block size is 512 ordering of data records is the same bytes and the block pointer size is 2 as or close to the ordering of data bytes, then the maximum order of + entries in some index. Then that the B tree is______. index is called [GATE-2017] a) Dense b) Sparse c) Clustered d) Unclustered [GATE-2015]

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission

ANSWER KEY:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 (b) (c ) (c ) (c ) (d) (a) (c ) (b) (c ) (a) (a) (a) (c ) (a) (a) 16 17 18 19 20 21 (b) (c ) 5 50 (a) 2

EXPLANATIONS

Q.1 (b) Now, B+ trees are preferred over the We know that indexing is better if the binary search trees as in B+ trees, data block is large. transfer of data from disk to Now, B+ trees are preferred over the primary memory is in form of data binary search trees as in B+ trees, blocks. These data blocks can store transfer of data is in form of data large information while transferring; blocks. These data blocks can store information on a single block is large information while transferring; more efficient. information on a single block is more efficient. Q.6 (a) Suppose all nodes are completely Q.2 (c) full that means every node has n-1 Size of disc block =512 keys. Size of index pointer = 4 Tree has 4 levels. If a new key is 4n+8(n-1) <= 512 inserted then at every level new 12n <= 520 node will be created. n<= 43.33 In worst case root node will also be n must be an integer, so degree is broken into two parts and we have 4 43. levels. So answer should be 5 Q.3 (c) because tree will be increased with Let the order of the internal node be one more level X, Q.7 (c) Then from the given, Nested Loop algorithm will involve (X -1)14 + 6X <= 512 n *b b block transfers. 14X -14 + 6X <=512, r s r 20X < 526 Either T1 can be R or T2 X =26 If r is T1 then total number of block access is 2000*20 + 80 = 40080 Q.4 (c) If R is T2 then total number of block p 1  key _ ptr _size + record _ ptr _size access is 400*80 + 20 = 32020 Better one is the second case, total + p block _ ptr _size 512   number of block accesses = (32020) Therefore p = 23 Q.8 (b) Q.5 (d) In nested loop join for each tuple in We know that indexing is better if first table we scan through the the data block is large. entire tuples second table.

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission

Here we will take table T2 as the outer table in nested loop join algorithm. The number of block accesses then will be 2 20+(400×80)=32020 In block nested loop join we keep 1 block of T1 in memory and 1 block of T2 in memory and do join on tuples.

For every block in T1 we need to load all blocks of T2. So number of

block accesses is Matching node is 20 25 which is 80*20+1620 The difference is 32020-1620 = one only. 30400 Q.12 (a) Q.9 (c) Only (i) and (ii) are correct. After From the structure of B+ tree we deleting 50 from the tree we are left can get the following equation: with node (20, 40) with 40 having n*p+(n-1)*(k + q) ≤ B no right subtree except 40 itself. where n= order, Nodes can’t combined because that p = tree/ block/index pointer, would overflow the node as they are q= record/ data pointer, already half –full or full. B= size of block So key 40 can be out in node In B+ tree, non leaf node has no containing 30, Height remains same record pointer: with 20 at root. (by putting q=0) N*p+(n-1)k≤ B Q.13 (c) n*6+(n-1)*9≤ 512 Type of Index = Secondary Index n≤34.77 (Key)  DENSE INDEX largest possible order of a non- leaf Size of the Key = 6 bytes node=34. Size of block pointer = 10 bytes Size of the Block = 1024 bytes Q.10 (a) Size of Index Record=10+6=16 bytes Let the order of leaf node is n. No of Index Records that can fit in a As per given, Block size = 1 k = 1024 single block =1024/16=64 ⟹ 6 + 7n + 9n = 1024 Total No of Index Records = DENSE ⟹ 16n = 1024 ⟹ n = 63 = 16384 index records Total No of Blocks for First Level Q.11 (a) Index = 16384/64=256 blocks

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission Total No of Blocks for Second Level In Clustered Index, data blocks are Index = 256/64=4 block stored in a way to match the index. Therefore, only one clustered index Q.14 (a) can be created on a given database We are given that the clustering table. index is defined on the fields. Now, if the records of the file are physically Q.18 (5) ordered on a non-key field since it is We can get all values in range from 7 a non-key, it will not have a distinct to 59 by accessing 5 nodes. value for each record. 1) First search 7 in a leaf node. Therefore, the clustering index is 2) Once 7 is found, linearly traverse defined on the fields of type non-key till 15 is found. and ordering. Q.19 (50) Q.15 (a) Let m be the order of B+ tree No. of splits would be three. This can m(8)+(m-1)12 <= 1024 be further displayed in the figure m <= 51. Since maximum order is below 51, maximum number of keys is 50. Insert 10 : 10 Insert 3 : 3,10 Q.20 (a) Insert 6 : B+ Trees  Balanced Trees  All leaf nodes are at the same level.

Q.21 (2) Let T1 and T2 be two registers, T1← b T2← c T1← (T1+ T2) T1← T1/3 T2← d T1← T1+ T2 T2←a T2← T2 – 1

T1← T1 * T2 Q.16 (b) Hence only 2 registers are required. In B+ tree, the root node has minimum 2 block pointers and maximum P block pointer where, P = order where, key=order -1 and in the non-root node, the minimum P number of keys 1 2 So, in the question key = 5, order = 6 So, minimum number of keys in 6 non-root node  12  2

Q.17 (c)

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission ASSIGNMENT QUESTIONS

Q.1 Which normal form is considered The next four questions are based on adequate for relational database the following details. Consider the given design? schemes. a) 2 NF b) 3 NF Branch_scheme = (Branch_name , assets , c) 4 NF d) BCNF Branch_city ) Customer_scheme = (Customer_name , Q.2 The concept of locking can be used street , Customer_city ) to solve the problem of Deposit_scheme = (Branch_name a) Lost update ,account_number, Customer_name,Balance) b) uncommitted dependency Branch_scheme = (Branch_name, c) Inconsistent data loan_number , Customer_name, amount ) d) deadlock Client_scheme = (Customer_name , Banker , banker_name ) Q.3 Given relations R (w, x) and S(x, y), the result of Q.7 Using relational algebra, the query SELECT DISTINCT w, x that finds customers who have a FROM R, S balance of over 1000 is Is guaranteed to be the same as R, if a) π customer_name( balance>1000(Deposit)) a) R has no duplicates and S is non- b) customer_name( balance > 1000 (Deposit)) empty c) customer_name ( balance> 1000 (Borrow)) b) R and S have no duplicates d) customer_name ( balance> 1000 (Borrow)) c) S has no duplicates and R is non- empty Q.8 Which of the following queries finds d) R and S have the same number of the clients of banker Agassi and the tuples city they live in? a) πclient_customer_name,customer_ Q.4 A functional dependency of the form city (σ client.customer_name = X  Y is trivial if customer.customer_name (σ a) Y ⊆ X b) Y ⊂ X banker_name = “Agassi” (Client  c) X ⊆ Y d) X ⊂ Y and Y⊂ X Customer))) b) π customer_name.customer_city(σ Q.5 If every non-key attribute is banker_name = “Agassi” (Client functionally dependent on the Customer)) primary key, then the relation will c) π client.customer_name.customer_ city (σ banker_name=”Agassi”( be in client.customer_name=customer.c a) First normal form ustomer_name (Client b) Second normal form Customer))) c) Third normal form d) π customer_name.customer_city d) Fourth normal form (σ banker_name=”Agassi” (Client Customer)) Q.6 The column of a table is referred to as the Q.9 Which of the following tuple a) tuple b) attribute relational calculus finds all c) Entity d) degree customers who have a loan amount of more than 1200?

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission a) {t (Customer_name)| tborrow Students:  t [amount] > 1200} (Roll_number, Name, Date_of_birth) b) {t | t(Customer_name) borrow Courses: t [amount] > 1200} (Course_number,Course_name, c) {t|  s borrow (t Instructor) [Customer_name] = s Grades: [Customer_name] s [amount] (Roll_number, Cource_name, Grade) > 1200)} SELECT DISTINCT Name d) None of the above FROM Students, Courses, Grades Where Q.10 Which of the following Domain Students.Roll_number=Grades.Roll_nu relational calculus finds all mber customers who have a loan amount AND Courses. Instructor = Korth of over 1200? AND Courses.Course_number = a) {| b, 1, a ( Grades. Course_number borrow  a>1200 )} AND Grades. Grade = A b) {| b, 1, a ( Which of the following sets is borrow a > 1200 ) } computed by the above query? c) { | borrow a) Names of the students who have a > 1200)} got an A grade in all courses d) { | borrow a > taught by Korth 1200)} b) Names of the students who gave Q.11 Given the function dependencies got an A grade in all courses X W; X Y; Y Z and Z PQ c) Names of the students who have Which of the following does not hold got an A grade in at least one of good? the courses taught by Korth a) X Z b) W Z d) None of the above c) X WY d) None of the above Q.15 Which of the following desired Q.12 What are the potential problems features are beyond the capability of when a DBMS executes multiple relational algebra? transactions a) Aggregate computation concurrently? b) Multiplication a) The lost update problem c) Finding transitive closure b) The dirty read problem d) None of the above c) The unrepeatable read problem d) The phantom problem Q.16 In airline reservation system, the

Q.13 The data flow model of an entities are date, flight number, application mainly shows place of departure, destination, type a) The underlying data and the of plane and seats available. The relationships among them primary key is b) Processing requirements and the a) Flight number flow of data b) Flight number + place of c) Decision and control information departure d) Communication network structure c) Flight number + date d) Flight number + destination Q.14 Consider the set of relations given below and the SQL query that Q.17 For a database relation R(a, b, c, d) follows: where the domains of a, b, c and d

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission include only atomic values, only the c) Operationally, x is deleted, so is y following functional dependencies d) Operationally, x is deleted, y and those can be inferred from them remains the same hold. a  c Q.22 A data model is a collection of b d conceptual tools for describing The relation is in a) Data and data relationship a) First normal form but not in b) Data semantics and consistency second normal form constraints b) Second normal form but not in c) Data, data relationship, data third normal form semantics, consistency constraints c) Third normal form d) None of the above d) None of the above Q.23 The employee information in a Q.18 Consider the following relation company is stored in the relation schema pertaining to a student Employee: (name, sex, salary, dept database. Name) Student: (rollno, name, address) Assume name is the primary key. Enroll: (rollno, courseno, course Consider the SQL query name) Select dept Name Where the primary keys are shown Form employee underlined. The number of tuples in WHERE sex = ‘M’ the student and Enroll tables are GROUP BY dept Name 120 and 8 respectively. What are the HAVING avg (salary) > (select avg maximum and minimum number of (salary) FROM Employee tuples that can be present in It returns the name of the (Student*Enroll), where ‘*’ denotes departments which the average salary natural join? a) Is more than the average salary a) 8, 8 b) 120, 8 in the company c) 960, 8 d) 960, 120 b) Of the male employee is more than the average salary of all the Q.19 In an E-R diagram ellipses represent male employees in the company. a) Entity sets c) Of the male employee is more b) Relationship among entity sets than the average salary of the c) Attributes employee in the same department. d) Link between attributes and d) Of the male employee is more entity sets than the average salary in the company Q.20 The set of permitted values for each Q.24 Choose the correct statements. attribute is called is a) Relational algebra and relation a) attribute set b)attribute range calculus are both procedural c) domain d) group query languages.

b) Relational algebra and relation Q.21 In an entity relationship, y is the calculus are both non- domain of entity and x is a procedural query languages. subordinate entity. Which of the c) Relational algebra is a following is/are incorrect? procedural query language and a) Operationally, if y is deleted, so x is relation calculus is a non- b) x is existence, dependent on y procedural query languages.

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission d) Relational algebra is a non- Q.30 Third normal form is inadequate in procedural query language and situations where the relation relation calculus is a procedural a) Has multiple candidate keys query languages. b) Has candidate keys that are composite Q.25 Choose the incorrect statements. c) Has overlapped candidate keys a) In network model, data is d) None of the above represented by a collection of records and relationship among Q.31 Redundancy is dangerous as it is data are represented by links. potential threat to data b) In hierarchical model, data and a) Integrity b) consistency relationships among data are c) Sufficiency d) none of the above represented by records and links respectively. Q.32 Let R be a relation. Which of the c) In hierarchical model, the following comments about the records are organized as a relation R are correct? collection of arbitrary Graphs a) R will necessarily have a d) In network model, the records if R is in BCNF but are organized as a collection of not in 4NF trees b) If R is in 3NF and if every key of R is simple, then R is BCNF Q.26 Students and courses enrolled, is an c) If R is in BCNF and if R has at example of least one simple key, then R is 4NF a) One-to-one relationship d) If R is in 3NF and if its every key b) one-to-many relationship is simple, then R is 5NF c) many-to-one relationship d) many-to-many relationship Q.33 An attribute of one table matching the primary key of another table, is Q.27 Relations produced from an E-R called as model will always be in a) Foreign key b) secondary key a) First normal form c) Candidate key d) composite key b) second normal form c) Third normal form Q.34 A primary key if combined with a d) fourth normal form foreign key creates a) Parent child relationship between Q.28 Choose the correct statement the tables that connect them a) An alternate key is a candidate b) many-to-many relationship key that is not a primary key between the tables that connect b) An alternate key is a primary key them that is not a candidate key c) Network model between the c) An alternate key is a candidate tables that connect them key that is also a primary key d) None of the above

d) None of the above Q.35 Choose the correct statement

a) Network models are complicated Q.29 E-R modelling technique is a by physical keys, but the relation a) top-down approach model is faster because it uses b) bottom-up approach logical keys c) left-right approach b) Network models are complicated d) none of the above by logical keys, but the relation

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission model is faster because it uses c) A condition the system tests for physical keys the validity of the database user c) Network models are complicated d) A statement that is executed by logical keys, but the relation automatically by the system as a model is slower because it uses side effect of a modification to physical keys the database d) Network models are complicated by physical keys, but the relation The next two questions are based on the model is slower because it uses following information logical keys Entity set TRANSACTION has the attributes transaction number, date, and amount Q.36 The employee salary should not be Entity set ACCOUNT has the attributes greater than Rs. 2000. This is account number, customer name, balance a) Integrity constraint b) referential constraint Q.40 Which is the discriminator of the c) over-defined constraint weak entity? d) feasible constraint a) Account number b) Transaction number Q.37 Manager’s salary details are hidden c) {Account number, date} from the employee. This is d) date a) conceptual level data hiding b) physical level data hiding Q.41 Which is the primary key of the c) external level data hiding weak entity? d) none of the above a) Account number b) {Account number, Transaction Q.38 The SQL expression number} SELECT distinct T.branch_name c) {Account number, date} from branch T, branch S Where d) {Transaction number, date} T.assets>S.assets and S.assets and s.branch_city = “PONDICHERRY” Q.42 Consider the relation Finds the names of EMPLOYEE (Emp-no, Emp-name, a) all branches that have greater salary, project-no, due-date) assets than any branch located in (Assuming an 1-1 relationship PONDICHERRY between project and employees) b) all branches that have greater Project-no is functionally dependent assets than all branch located in on PONDICHERRY a) Emp-name b) Emp-no c) all branches that has the greatest c) due-date d) none of the above assets in PONDICHERRY d) any branches that has greater Q.43 In the previous question, which of assets than any branch located in the following is/are functionally PONDICHERRY dependent on Emp-name? (Assume no two persons have the same name) Q.39 A trigger is a) Emp-no a) A statement that enable to start b) Project-no, salary any DBMS c) Salary, due date b) A statement that is executed by d) Emp-no, salary, project-no, due the user when debugging an date application program

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission Q.44 Let R(a, b, c) and S(d, e, f) be two A  BC relations in which d is the foreign B C key of S that refers to the primary A B key of R. Consider the following four AB C operations. The canonical cover for this set is a) Insert into R b) Insert into S a) A BC and B C c) Delete from R d) Delete from S b) A BC and AB C Which of following is true about the c) A BC and A B referential integrity constraint above? d) A B and B C a) None of them can cause any violation Q.50 Assume transaction A holds a b) All of the can cause violation shared lock R. If transaction B also c) Operations a) and b) can cause requests for a shared lock on R, it will violation a) Result in a deadlock situation d) Operations b) and c) can cause b) Immediately be granted violation c) Immediately be rejected d) B granted as soon as it is Q.45 Which of the following schemes are released by A used for ensuring atomicity? a) Log with deferred modification Q.51 The index consists of b) Log with immediate modification a) A list of keys c) Shadow paging b) Pointers to the master list d) None of the above c) Both a) and b) d) All of the above Q.46 If P and Q are predicates and P is the relational algebra expression, then Q.52 An audit trail which of the following equivalence a) Is used to make back-up copies are valid? b) Is the recorded history of a)  P ( Q (e)) = Q( P (e))_ operations performed on a file ? b) P ( Q (e)) = P  Q (e) c) Can be used to restore lost c) Q ( P (e)) = P Q (e) information d) None of the above d) All of the above Q.53 A scheme describes Q.47 Generally speaking, for a weak a) Data elements entity set to be meaningful it must b) Records and files be part of a c) Record relationships a) One-to-one relationship d) All of the above b) One-to-many relationship c) many-to-many relationship Q.54 What is the abbreviation used for a d) None of the above software package that permits the users to create, retrieve and Q.48 If a relation scheme is in BCNF, then maintain records in a data base? it is also in a) DASD b) FMS a) First normal form c) EMMS d) DBMS b) Second normal form c) Third normal form Q.55 In order to use a record d) None of the above management system Q.49 Consider the following set of a) You need to understand the low functional dependencies on the level details of how information scheme (A, B, C). in stored

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission b) You need to understand the a) You enter the search value into model the record management the form system uses b) You look at each form c) Both a) and b) sequentially until you see the d) All of the above one you want c) You type the key in an entry line, Q.56 A form defines and the correct form is displayed a) Where data is placed on the d) All of the above screen b) The width of each field Q.63 What name is given to the collection c) Both a) and b) of facts, items of information or d) All of the above data, which are relation in some way? Q.57 A top-to-bottom relationship among a) Data base the items in a data base is b) Directory information established by c) Information tree a) Hierarchical schema d) Information provider b) Network schema c) Relational schema Q.64 In any hierarchy of data d) All of the above organization, the smallest entity to be processed as a single unit called Q.58 In a relational schema, each tipple is a) Data field b) Data record divided into fields called c) Data file d) Data base a) Relations b) Domains c) Queries d) All of the above Q.65 A network schema a) Restricts the structure to a one- Q.59 A logical schema to-many relationship a) Is the entire data base b) Permits many to many b) Is a standard way of organizing relationships information into accessible parts c) Stores data in tables c) Describes how data is actually d) All of the above stored on disk d) All of the above Q.66 A number of related records that are treated as a unit is called Q.60 Which of the following are not a a) File b) Field relational data base? c) Data d) Batch a) DBASE IV b) 4th Dimension c) FoxPro d) Reflex Q.67 Which two files are used during operation of the DBMS? Q.61 Which of the following contains a a) Query language and utilities complete record of all activity that b) Data manipulation language and affected the contents of a data base query language during a certain period of time? c) Data dictionary and transaction a) Report write log b) Query language d) Data dictionary and query c) Data manipulation language language d) Q.68 A transparent DBMS Q.62 When performing a look-up operation using a form

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission a) Cannot hide sensitive formula that transforms a file key information from users into a record location in b) Keep its logical structure hidden a) A tree file b) An indexed file from users c) A hashed file d) A sequential file c) Keeps its physical structure hidden from users Q.75 The relational model uses some d) Both b) and c) unfamiliar terminology. A tuple is equivalent to a Q.69 Related fields in a data base are a) Record b) Field grouped to form c) File d) Data base a) Data file b) Data record c) Menu d) Bank Q.76 Which command (&) is (are) used to redefine a column Q.70 Goals for the design of the logical of the table in SQL ? schema include a) ALTER TABLE a) Avoiding data inconsistency b) DEFINE TABLE b) Being able to construct queries c) MODIFY TABLE easily d) None of the above. c) Being able to access data efficiently Q.77 In SQL, the ALTER TABLESPACE d) All of the above Command is used a) To add/rename data files Q.71 The designer of a form includes b) To change storage a) Filed designators characteristics b) Prompts c) To take a table space c) Data online/offline d) None of the above. d) To begin/end a backup.

Q.72 Batch processing is appropriate if Q.78 In SQL which command(s) is/are a) A large computer system is used to enable/disable a data base available trigger? b) Only a small computer system is a) ALTER TRIGGER available b) ALTER DATABASE c) Only a few transactions are c) ALTER TABLE involved d) MODIFY Trigger d) All of the above

Q.73 A multiple-form file management Q.79 In SQL, which command(s) is (are) system used to issue multiple CREATE a) Let's you define different forms TABLE, CREATE VIEW and GRANT for different operations statements in a single transaction? b) Lets you create a look-up form a) CREATE PACKAGE with an associated read-only b) CREATE SCHEMA password to prevent access c) CREATE. CLUSTER by unauthorized users d) All of the above c) Both a) and b) d) Allow you to entry data in all Q.80 In SQL, which command(s) is (are) forms used to remove rows from a table. a) DELETE b) REMOVE Q.74 The physical location of a record is c) TRUNCATE d) Both a) & c) determined by a mathematical

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission Q.81 In SQL, which of the following is not a data definition language Q.87 Which of the following free from commands data base of IBM and compatible a) RENAME b) REVOKE personal computers? c) GRANT d) UPDATE a) memory Mate b) Q and A c) Paradox . d) Double Helix Q.82 For a data base relation R (a, b, c, d), where the domains of a, b, c, d. Q.88 A report generator is used to include only atomic values, only the a) update files following functional dependencies b) print files on paper and those that can be inferred from c) data entry them hold a→c b→d. The relation is d) all of the above a) the first normal form but not in second normal form Q.89 When you have finished entering b) in second normal form but not in information into a form? third normal form a) the template is written to the c) in third normal form data file d) none of the above. b) the contents of the form are written to the data file Q.83 If a piece of data is stored in two c) the contents of the form can be places in the data base, then printed a) storage space is wasted d) all of the above b) changing the data is one spot will cause data inconsistency Q.90 What is the language used by most c) it can be more easily accessed of the DBMSs for helping their users d) both a)and b) to access data? a) High level language Q.84 A compound key b) Query language a) is made up a several pieces of c) SQL information d) 4GL b) uniquely identifies an item in a list c) both a)and b) Q.91 A number of related records that are d) is a combination of each unique treated as a unit is called key a) file b) field c) data d)batch Q.85 A data dictionary doesn't provide information about Q.92 Updating a data base means a) where data is located a) revising the file structure b) the size of the disk storage device b) re-organizing the data base c) who owns or is responsible for c) modifying or adding record the data occurrences d) how the data is used d) all of the above

Q.86 What name is given to the collection Q.93 Information can be transferred of facts, items of information or data' between the DBMS and a which are related in some way? a) spread sheet program a) Data base b) word processor program b) Directory information c) graphics program c) Information tree d) all of the above d) Information provides

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission Q.94 If a calculation is embedded in a Q.100 Versatile report generators can form provide a) the result of the calculations are a) Columnar totals stored with the form b) Sub-totals b) the calculations are stored with c) Calculations the form d) All of the above c) the result of the calculations are printed in report Q.101 The files stored on a secondary d) all of the above stage device are composed of a hierarchy of data. What does a Q.95 A large computer information record in a file contain? system maintains many different a) Bits b) Characters computer files. Which amongst them c) Data field d) Schema is called a perpetual file? a) Specialized file b) Log file Q.102 The language used in application c) master file d) Update file programs to request data from the DBMS is referred to as the Q.96 When using a data base a) DML management system, the first thing b) DDL that you must do is to c) QUERY language a) create a data base file d) All of the above b) activate file editor c) load the software into your Q.103 Which of the following is a type of micro- computer DBMS software? d) keep a floppy disk in readiness a) data base manipulation language Q.97 Data encryption techniques are b) query language particularly useful for c) utilities a) reducing storage space d) report writer requirements b) improving data integrity Q.104 The data dictionary tells the DBMS c) protecting data in data a) what files are in the data base communication systems b) what attribute are possessed by d) all of the above the data c) what these files contain Q.98 Long-range planning report d) all of the above produced in an MIS are primarily designed for Q.105 To have a file hold a list, it is a) top management necessary to b) middle management a) identify the records in the list c) lower management b) identify the name, width and d) all of the above type of the fields of each record

Q.99 Queries to a database c) decide which fields will be used a) are written in English as sort or index keys b) can use aggregate functions like d) all of the above SUM and COUNT c) both a)and b) Q.106 With respect to data input, the most d) all of the above accurate description of batch control is

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission a) dividing documents to be Q.112 The collection of information stored entered into batches in a database of a particular moment b) controlling the input of each is...... input clerk a) view b) schema c) comparing to a pre-calculated c) instance d) subschema figure the total of a data item summed across a batch records Q.113 Construct an E - R model for the put into the system . below assumption and find out the d) all of the above degree of the relationship. A technician uses exactly one Q.107 The relational model uses some notebook for each project. Each unfamiliar terminology. A tuple is notebook belongs to one technician equivalent to a for each project. Note that a a) record b) field technician may still work on many c) file d) data base project and maintain different notebooks for different projects. Q.108 Which of the following is not an a) unary b) binary advantage of the data-base approach? c) ternary d) two binary relations a)elimination of the data

redundancy Q.114 1:N relationships in E-R diagram is b) ability to associate related data implemented in relational model as c) increased security a) foreign keys are added on both d) all of the above are advantages. sides

b) relation corresponding to '1' is Q.109 Which of the following command is modified to include foreign key (are) used to recompile a stored of the relation on the 'N' side procedure in SQL? c) primary keys are added on a) COMPILE PROCEDURE bothsides b) ALTER PROCEDURE d) relation corresponding to 'N' c) MODIFY PROCEDURE side is modified to include foreign d) All of the above key of the relation on the '1' side Q.110 In SQL, which command(s) is (are) used to enable/disable all triggers Q.115 An entity relationship diagram is a on a table? tool to represent a) ALTER TRIGGERS a) Data model b) ALTER, TABLE b) Process model c) MODIFY TRIGGERS IN TABLE c) Event model d) All of the above d) Conceptual model

Q.111 Aggregation is Q.116 The process of designation sub a) An abstraction through which grouping within an entity set is relationships are treated as called lower level entities. a) Specialization b) Generalization b) An abstraction through which c) Aggregation d) Instantiation relationships are treated as higher level entities. Q.117 The data in the database at c) An abstraction through which particular moment of time is called relationships are not treated at a) Schema b) Snapshot all as entities. c) Intension d) Extension d) All the above

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission Q.118 A primary key for an entity is a) Class diagram a) A candidate key b) Use case diagram b) Any attribute c) Activity diagram c) A unique attribute d) Implementation diagram d) A super key Q.127 The diagram which shows the Q.119 Conceptual schema is transformed system components of their inter - from high level data model into the connections, both at the software implementation data model. This component level and the hardware step is called component level is a) Data model mapping a) Class diagram b) Conceptual schema b) Use case diagram c) Functional mapping c) Activity diagram d) Conceptual operation d) Implementation diagram

Q.120 Singleton is Q.128 Entities of specified type can be a) A set with only one element grouped into, b) A set with a ton of element a) Database b) Entity set c) A single value c) Attribute d) Table d) A key attribute of an entity value Linked Answer Questions for Q. No. Q.121 Weak entity type is known as Q.129 & Q.130 a) Parent entity type b) Dominant entity type Q.129 The primary keys are required for c) Child entity type mapping following ERD: d) Co-ordinate entity type

Q.122 A super key for an entity consists of a) One attribute only a) 1 b) 2 b) At least two attributes c) 3 d) 4

c) At most two attributes Q.130 How many foreign keys are required d) One or more attributes for above relations. Q.123 Relation type are called a) 1 b) 2 a) Association b) Aggregation c) 3 d) 4

c) Links d) Discrimination Q.131 Which multi valued dependency is Q.124 Link attribute is not followed from the following a) A relationship attribute table? b) A discriminator ENAME PNAME DNAME c) A relationship tuple Smith X John d) A link tuple Smith Y Anna Smith X Anna Q.125 Ontology is similar to Smith Y John a) a) ENAME→ PNAME b)Logical schema b) ENAME→DNAME c)Conceptual schema c) PNAME →ENAME d)Sub schema d) None

Q.126 The diagram which depicts the flow of task between various components Q.132 Consider the two relations student of a system is (name, rollno, deptno, rank) and

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission course (deptno, rollno, deptname, the correct answer to the above teacher, marks). Which of the question. following queries cannot be a) [M1, M2, M3, Pl.) expressed using the basic relational b) (M1, P1, N1, N2} algebra operations (U, -,x, π, σ, p)? c) (M1, P1, N1) a) Rank of every student in a d) (M1, P1) department b) Students whose name is the Q.137 Indicate which of the following same as their department name statements are true: A relation c) The sum of all marks for a database which is in 3NF may still particular course have undesirable data redundancy d) All students of a given because there may exist: department a) transitive functional dependencies b) non-trivial functional Q.133 In one to many relationship, Entity dependencies involving prime type on one side of relationship called attributes on the right side a) Parent b) Child c) non-trivial functional c) Subtype d) Super type dependencies involving prime attributes only on the left side Q.134 What will be the number of relations d) non-trivial functional if we follow ER-to-Relational Mapping dependencies involving only Algorithm? prime attributes

Q.138 Let us consider the following declaration R represents n entity and the set X, Y of attributes represents the key of R then if R represents a one-to-one relationship between entity E1 and E2 then which of the a) 3 b) 4 following is correct? c) 5 d) 6 a) The FDY→ X will hold only b) The FD X→Y will hold only Statement for Linked Answer Questions c) a) and b) hold together Q.135 & Q.136 d) Neither a) nor b) holds Consider the following ER Diagram Q.139 Given two sets of Function

Dependencies (FDs) F and G over a relation scheme R if G covers F and if no proper subset G'(G'⊑G) covers F, then G is called a) determinant cover b) nonredundant cover c) nondeterminant cover Q.135 The minimum number of tables d) redundant cover needed to represent M, N, P, R1, R2 is a) 2 b) 3 Q.140 Spurious tuples are c) 4 d) 5 a) the multiple entries with same value Q.136 Which of the following is a correct b) the tuples with null values that attribute set for one of the tables for exist in the original relation

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission c) the tuples with null values that a) 1 b) 2 did not exist in the original c) 3 d) 4 relations d) the tuples with null values Q.147 Second NF related with a) Atomic Data Q.141 If F is a set of FDs on a relation b) Full functional dependency scheme R then F+, the closure of F is c) Option A and B are compulsory the smallest set of FDs such that F+ d) None of these is in 3NF and no FD can be derived from F by using the interference Q.148 Which of the following can be used axioms that are not contained in F+ to represent "No seat is booked by a) it is assumed to contain all the more than one person"? attributes that appear in F a) ∃s ∃p ∃q {[B(p,s)∧B(q,s)]->(p=q)} b) whole statement is incorrect b)∀s ∀p ∀q {[B(p,s)∧B(q,s)]->(p=q)} c) F+ i.e. closure is not possible c) ∃s ∃p ∃q{[B(p,s)UB(q,s)]->(p=q)} d) none of these d)∀s∀p ∀q{[B(p,s) U B(q,s)]->(p=q)}

Q.142 A primary key if combined with a Q.149 Suppose you are given a relation R foreign key creates z with four attributes ABCD. For the a) many- to -many relationship set of FDs, assuming those are between the tables that connect the only dependencies that hold for them R, do the following: b) network model between the C→D, C →A, B →C tables that connect them Suppose, the relation is decomposed c) parent child relationship between into 3 relations AC, BC, CD. Which of the tables that connect them the following is true? d) none of the above a) Lossless, Dependency preserving b) Lossless, Not dependency Q.143 If all attributes are candidates key in preserving relation, then it is in c) Not lossless, Dependency a) 1 NF b) 2 NF preserving c) 3 NF d) BCNF d) Not lossless, Not dependency Linked Answer Questions for Q.No. preserving Q.144 & Q.145 Suppose you are given relation R(X,Y,Z,W) Q.150 For a database relation. R(a, c, d), with functional dependencies XY->Z, ZW- Where the domains of a, b, c, d >X and Y->W include only atomic values, only the following functional dependencies Q.144 How many keys (minimal) are there and those that can inferred from in R? them hold: a) 1 b) 2 a →c c) 3 d) 4 b →d The relation is Q.145 The highest normal forth of R is a) In first normal form but not in a) 1NF b) 2NF second normal form c) 3NF d) BCNF b) In second normal form but not in third normal form Q.146 R(X, Y, Z, W) having FDs {X→Y; Y→Z; c) In third normal form Z→W; W→X} So number of d) None of the above candidate Keys

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission Q.151 Let R(a, b, c) and S(d, e, f) be two (πcname(Deposit) πcname (Borrow)) relations in which d is the foreign Query 4: key of S that refers to the primary Select cname from Deposit d where key of R. Consider the following exists (select * from Borrow .b four operations on R and S where b .cname=d.cname). a) Insert into R b) Insert into S Which of the following statements c) Delete from R d)Delete from S is/are false? Which of the following statements is a) Query 2 is a natural join true about the referential integrity operation constraint above? b) Query 1 and query 2 gives same a) None of a), b), c) or d) can cause result its violation c) Both A and B b) All of a), b), c) or d) can cause its d) None violation c) Both a) and d) can cause its Q.155 Tuple relational calculus is a violation a) Procedural language d) Both b) and c) can cause its b) Non - procedural language c) Materialized language Q.152 Relational algebra is a ______query d) Non - materialized language. language a) Procedural b) Structural Q.156 Domain relational calculus is c) Objected oriented d) None a) Procedural language b) Non - procedural language Q.153 Let R1 (A, B, C, D) and R2 (D, E) be c) Materialized language two relation schema, where the d) Non - Materialized language primary key sare, shown underlined, and let C be a foreign key in R1 Q.157 Consider the following statements: referring to R2. Suppose there is no S1: (∏ename (emp)) violation of the above referential S2: Select ename from emp integrity constraint in the Which of the following is true? corresponding relation instances r1 a) Both S1, S2 give same output and r2 which one of the following b) Duplicates may get printed in S1 relational algebra expressions c) Duplicates may get printed in S2 would necessarily produce an d) None empty relation? a) ∏D(r2)-∏C(r1) Q.158 In tuple relational calculus ∀t ∈r b) ∏C(r1)-∏D(r2) (A1(t)) equivalent to c) ∏D(r1⋈C≠Dr2) a) ⇁∃t ∈ r (⇁A1 (t)) d) ∏C(rl⋈C=Dr2) b) Et (--,A1 (r)) c) E t r (-1A1 (t)) Q.154 Deposit (acno, cname, bal, bname) d)atEr(-1A1 (r)) Borrow (lno, cname, amt, bname) Query 1: Q.159 Consider the relation schemas as {t/3S∈ Deposit (t [cname] = s follows. [cname]) ∧∃u∈ Borrow (t works(person name, company [cname] = u [cname])} name, salary); Query 2: lives (person name, street, city); (πcname (Deposit ⋈ Borrow) located in (company name, city); Query 3: Relational algebra expression for

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission Find the names of the persons who SUPPLIERS(sid:integer,sname:string, work for company 'FBC' (company address:string) name='FBC'). PART(pid:integer, pname:string, a) πperson name (σcompany name= FBC (works)) color:string) b) πcompany name=FBC (σperson name CATALOG(sid:integer, (works)) pid:integer,cose:real) c) πperson name (σworks (company name =Q.162 What does the following SQL query FBC)) return? d) πperson name (σcompany name=FBC (works X SELECT c.sid FROM CATLOG c, lives)) PARTp WHERE (p.color ='red' OR p.color = 'green') and p.pid = c.pid Q.160 Select the tuples for all employees a) Find sids of suppliers who who either work in department 4 supply some red and green part and make over $ 25000 per year or b) Find the sids of suppliers who each in department 5 and make over supply some red or green parts $ 30,000, refers to c) Find sids of suppliers who supply a) σ(DNO=4 AND SALARY > 25000) every red and every green part OR (DNO = 5 AND SALARY > d) Find sids of suppliers who supply 30000)(EMPLOYEE) every red or every geeen part b) π(DNO=4 AND SALARY>= 25000)OR (DNO = 5 AND Q.163 What does the following SQL query SALARY > 30000) (EMPLOYEE) return? c) σ(DNO=4 OR SALARY > 2500)OR SELECT s.sid FROM SUPPLIERS s (DNO=5 OR SALARY>3000) where s.address = '221 packer (EMPLOYEE) street' OR s.sid IN (SELECT c.sid d) σ(DNO=4 OR SALARY> 30000) FROM PART p, CATALOG c where OR (DNO=4 AND SALARY> p.color='red' AND p.pid = c.pid) 25000) (EMPLOYEE) a) Find sid of supplier who supply some red part or are at 221 Q.161 Consider the Query SELECT student packer street name FROM student WHERE class b) Find sid of supplier who supply _name=(SELECT class-name FROM some red part and at 221 packer students WHERE math_marks=100); street What will be the output? c) Find sid of supplier who supply a) The list of names of student with all red part and at 221 packer 100 marks in mathematics street b) The names of all students of all d) None of these classes in which at least one student has 100 marks in Q.164 Consider the query SELECT student mathematics name FROM student data WHERE c) The names of all students in all roll no in (SELECT roll no FROM classes having 100 marks in student marks WHERE mathematics SEM1_MARK=SEM2 MARK); Which d) The names and class of all of the following is true? students whose marks in a) It gives the name of the student mathematics is 100 whose marks in semester1 and semester2 are not same Common Data for Question 162 and 163: b) If gives all the names and roll Consider the following no's of those students whose

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission marks in semester 1 and where students. Roll - number = semester 2 are same Grades .Roll - number and courses . c) It gives the names of all the Instructor = Korth and Courses . students whose marks in Course - number = Grades . Course - semester 1 and semester2 are number and Grades . grade = A same Which of the following sets is d) It gives roll no's of all students computed by the above query? whose marks in semester1 and a) Names of students who have got semester2 are same. an A grade in all courses taught by Korth Q.165 Consider the employee table EMP b) Names of students who have got (id, salary) with id as primary key. an A grade in all courses. Consider the following queries for c) Names of students who have got obtained an id, with kth highest sal an A in at least one of the (with a given k) courses taught by Korth Query 1. Select id d) None of the above from EMP E1 where k = (select Q.168 SQL query is SELECT A FROM B count (*) from WHERE C can be expressed as. EMP E2 where E2. a) πC (σA b)) b) πA (σC b)) Ei.sal) c) πB (σA c)) d) πC (σB a)) Query2 Select id from EMP E2 Q.169 Consider the following schedule S where k -1 = (select S : R1a) R2b) Commit 2 R3c) W1a) count (*) from EMP R3a) W1b) Rollback 1 W3a) R4b) E2 where E2. SAL> What is the category of the schedule Ei.sal) with respect to recoverability? a) Both query 1 and query2 are a) Recoverable schedule correct b) Cascading rollback schedule b) Only quer1 is correct c) Non-recoverable schedule c) Only query2 is correct d) Cascadeless rollback schedule d) None of the above Q.170 Consider the following relational Q.166 A time stamp is a combination of schema: a) Data and time Suppliers(sid:integer, sname:string, b) Data and day city:string, street:string) c) Month and year Parts(pid:integer, pname:string, d) Second and fraction of second color:string) Catalog(sid:integer, pid:integer, Q.167 Consider the set of relations shown cost:real) below and the SQL query that Consider the following relational follows. Students : (Roll - query on the above database: number, Name, Data - of - birth) SELECT S.srame Courses : (Course number, course - FROM Suppliers S name, instructor) WHERE S.sid NOT IN (SELECT C.sid Grades : (Roll - number, Course - FROM Catalog C number, Grade) WHERE C.pid NOT (SELECT P.pid Select distinct Name from Students, FROM Parts P WHERE P.color< > Courses, Grades 'blue'))

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission Assume that relations records respectively. Assume Disk corresponding to the above schema blocks size of 1024 bytes and main are not empty. Which one of the memory buffers size is 7 blocks. following is the correct Then which of the following query interpretation of the above query? plan is cost effective (considering a) Find the names of all suppliers nested loop join strategy)? who have supplied a blue part a) STUDENT |X|S.DEPTNO=D)DEPTNO b) Find the names of all suppliers DEPT who have not supplied a blue b)DEPT|X|s.DEPTNO=D)DEPTNO STUDENT part c) σS.DEPTNO=D)DEPTNO(STUDENT x c) Find the names of all suppliers DEPT) who have supplied a non-blue d) ALL are equivalent cost effective part. d) Find the names of all suppliers Q.175 In a database, a transaction P holds who have not supplied a non- a shared lock S. If transaction Q also blue part. request for a shared lock on S then. a) The system is in deadlock Q.171 Following statements belongs to DDL b) It is granted to Q only if P release it a) Create b) Drop c) Immediately it will be granted c) Alter d) All of above d) Immediately it will be rejected

Q.172 Which of the following is valid SQL Q.176 Consider a non serial schedule S has for an Index? 4 transaction and the execution of a) CREATE INDEX ID; operation is given below: b) CHANGE INDEX ID; S: R1a), R4b), W3a), W2b), W4c), c) ADD INDEX ID; commit4, W3c), W1a) comit1, R2d), d) REMOVE INDEX ID; W3d), Rollback3; The above given Schedule is ______. Q.173 The HAVING clause does which of a) Non recoverable schedule the following? b) Recoverable schedule a) Acts like a WHERE clause but is c) Cascading rollback schedule used for groups rather than d) Cascade less rollback schedule rows. b) Acts like a WHERE clause but is Q.177 Consider the following non serial used for rows rather than schedule: columns. S: R1a), R2b), R3c), W1a), R2a), c) Acts like a WHERE clause but is W2b), R3b), W2a),R1c), W3b), used for columns rather than commit1, commit2, commit3. It is groups. not allowed under which of the d) Acts EXACTLY like a WHERE following protocols? clause. a) Mutliversion Timestamp protocol b) Basic Timestamp protocol Q.174 Consider two large files for keeping c) Basic 2PL STUDENT and DEPT records, d) Rigorous 2PL maintained in a database. Each Q.178 The following property makes sure STUDENT and DEPT records are of that concurrent transaction do not size 100 bytes and 20 bytes interact respectively. The STUDENT and a) Atomicity b) Consistency DEPT files contain 30000 and 200 c) Isolation d) Durability

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission Q.179 Atomicity is managed by a) Transaction management Q.184 In conservative 2 phase locking component protocol, b) Recovery management a) All exclusive locks are released component before transaction commits c) Concurrency control component b) All locks must held before d) None transaction c) Create read & write list before Q.180 Isolation is managed by holding any lock a) Transaction management d) None of these component b) Recovery management Q.185 Consider the following transaction component T1 T1 c) Concurrency control component Read items d) None (X);

Q.181 The timestamp schedule which X = X-N; accepts view serializable Read item (X);

schedule is: X = X+ N; a) Basic timestamp b) Thomas write rule Write item (X); c) Both a) and b) Write item (X); d) None Read items (Y); Q.182 In a multiple granularity protocol, et

us assume that a Transaction T1 holds a data item 'D' in Intensive Y/: = Y+N; exclusive mode. Then which of the Write item (Y); following lock requested by another transaction T2 can't be granted. Suppose the number of seats in a a) Intension shared flight is 80.If there were so b) Intension exclusive reservation on the flight (X), c) Both A and B transfers 5 seat reservations for the d) Shared flight corresponding to X to the flight corresponding to Y and Q.183 Consider the relation R(W X Y Z) reserves 4 seats on X. then what is with the FD set final result should come and what F={X→Z,Z→X,WX→Y}. has come according to the Which of the following is true? transaction? a) {R1(XZ),R2(WXY)} forms BCNF a) 70, 84 b) 79, 84 decomposition for R and it c) 84, 79 d) None of these satisfies both lossless and dependency preserving conditions Q.186 Which of the following statements is b) {R1(XZ),R2(WYZ)} forms BCNF false for Time-stamp ordering decomposition for R and it will protocol of database concurrency satisfy lossless join condition but control management? dependencies are not preserved. a) It always ensures conflict c) Neither A nor B serializability property d) Both A and B b) It always ensures deadlock free

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission c) It always ensures recoverable a) Last block b) First block schedule c) Overflow block d) None d) Both B and C Q.193 A B+ tree of order n index file each Q.187 Consider three transactions Ti, T2 leaf node must contain and T3, executing in a RDBMS a) n -1 values b) n - 2 values c) n/2 values d)(n-1)/2 values environment according to the following schedule S:. The schedule S is a) Conflict- serializable to Q.195 Each block of B-Tree holds space for, but not recoverable a) n search key, n+1 pointer b) Conflict-serializable to b) n + 1 pointer, n search key and recoverable c) n search keys n pointer c) Conflict-serializable to d) cannot be determined

and recoverable Common Data for Q. No. 196 & 197 d) Conflict-serializable to Consider a DBMS that has the following but not recoverable characteristics: 2KB fixed-size blocks Q.188 The solution to the recurrence 12-byte pointers  relation T n  4T n logn is 56-byte block headers a) O(lognloglogn) b) O(loglogn) We want to build an index on a search key c) O(log2n) d) O(logn2) that is 8 byte long.

Q.196 What is maximum number of Q.189 An indexing operation is records we can index with a 3-level a) Sorting a file using a single key (2 levels plus root) B+ Tree. b) Sorting a file using two keys a) 990000 b) 100000 c) Ordering of the record based on c) 9900 d) None of the above search key value d) Both (b) and (c) Q.197 What is maximum number of records we can index with a 3 level Q.190 Index consists of B Tree a) A list of keys a) 238327 b) 384399 b) Pointer to the record c) Both A or B d) None of the above c) Both b) and a) d) None Q.198 Which one of the following statements about normal forms is Q.191 Main advantage of B tree is FALSE? a) reduce searching time a) BCNF is stricter than 3NF b) reduce redundant storage of b) Lossless, dependency-preserving search key value. decomposition into 3NF is c) Increase through put of the always possible system c) Lossless, dependency-preserving d) None decomposition into BCNF is

Q.192 In sequential file organization if a always possible record is not fit in free space then d) Any relation with two attributes the record is placed in is in BCNF

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission Common Data for Q. No. Q.199 & 200 Q.199 Choose the correct option Suppose the following two processes, foo a) Concurrent execution of these and bar are executed concurrently and two processes can result in one share the semaphore variables S and R or both being blocked forever (each initialized to 1) and the integer b) It cannot lead to deadlock variable x (initialized to 0). c) Incorrect use of semWait() void foo ( ){ void bar ( ){ d) Incorrect use of semSignal() . do { do { semWait (S); semWait (S); Q.200 Choose the correct option semWait(R); semWait(R); a) Concurrent execution of these x++; x--; two postponement of one of them semSignal (S); semSignal (S); b) Concurrent execution of these semSignal(R); two postponement of one of them semSignal(R); } while (1); c) Incorrect use of Semwait() } while (1); } d) Incorrect use of Semsignal() }

ANSWER KEY:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

(b) (a) (a) (a) (c) (b) (a) (a) (c) (b) (b) (a) (b) (c) (a)

16 17 18 19 20 21 22 23 24 25 26 27 28 29 30

(c) (a) (a) (c) (c) (c) (c) (d) (c) (c) (d) (c) (a) (a) (a)

31 32 33 34 35 36 37 38 39 40 41 42 43 44 45

(a) (a) (a) (a) (a) (a) (c) (a) (d) (b) (b) (b) (a) (d) (a)

46 47 48 49 50 51 52 53 54 55 56 57 58 59 60

(a) (b) (a) (d) (b) (b) (d) (d) (b) (c) (a) (b) (b) (d) (d)

61 62 63 64 65 66 67 68 69 70 71 72 73 74 75

(a) (a) (a) (b) (a) (c) (c) (b) (d) (d) (d) (c) (c) (a) (a)

76 77 78 79 80 81 82 83 84 85 86 87 88 89 90

(d) (d) (c) (b) (d) (d) (a) (d) (c) (b) (a) (a) (b) (b) (b)

91 92 93 94 95 96 97 98 99 100 101 102 103 104 105

(a) (c) (d) (b) (c) (c) (c) (a) (b) (d) (c) (a) (a) (d) (d) 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 (c) (a) (d) (b) (b) (b) (c) (c) (d) (d) (a) (b) (c) (a) (a) 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 (c) (d) (c) (a) (c) (c) (d) (b) (b) (b) (c) (c) (a) (b) (b) 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 (a) (a) (c) (b) (c) (a) (c) (d) (b) (a) (d) (c) (b) (a) (a) 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 (d) (a) (b) (b) (b) (b) (c) (a) (a) (a) (a) (b) (a) (a) (b) 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 (a) (c) (c) (b) (b) (d) (a) (a) (b) (c) (d) (d) (c) (a) (c) 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 (c) (d) (d) (b) (c) (d) (d) (a) (c) (c) (b) (c) (d) (d) (a) 196 197 198 199 200

(a) (c) (c) (a) (b)

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission EXPLANATIONS

Q.1 (b) average salary of male employees Adequate level of database design is department wise. 3NF. Q.24 (c) Q.4 (a) Relational Algebra is procedural If Y  X, then XY is trivial. language, Relational Calculus is non- procedural language. Q.5 (c) If all non-key attributes depends on Q.25 (c) primary key, it is 3NF definition. Hierarchical model is based on graphs and Network model is based Q.7 (a) on trees. First selection then projection must be applied. Q.26 (d) One student can enroll for more Q.11 (b) than one course. And one course is a, c can be get with transitive opted by more than one student. property. Q.28 (a) Q.14 (c) Alternate key is secondary key. It is The join returns a record even if we a candidate key other than primary have one matching. key. Q.31 (a) Q.16 (c) The problems due to redundancy The same flight number flies on are consistency and integrity. different dates. So the combination is key. Q.33 (a) The primary key of one table Q.17 (a) becomes foreign key in another table. ab combination is the key. Since c is depending on part of the key, it is Q.36 (a) not in 2NF. Check constraint is integrity constraint. Q.18 (a) Maximum and Minimum would be Q.39 (d) only the students=(8,8) Since student Trigger automatically executes when table is parent and enroll is child. condition associated with it matches when DB modification is done. Q.21 (c) When parent is deleted, then child is Q.42 (b) deleted. The converse is not true. Emp_no is primary key which can identify project_no. Q.23 (d) Q.43 (a) Subquery returns salary of the Since emp-name behaves like a key, company and main query gets all attributes are dependent on it.

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission Q.44 (d) In the database, a snapshot is the Insertion into child table and deletion state of a database at a particular from parent table can cause point of time. violation. Q.118 (c) Q.46 (a) Primary Key should be a unique Selection operation is commutative. attribute.

Q.49 (d) Q.119 (a) This step is called Data model mapping

Q.120 (a) A set with only one element

Q.121 (c) It is known as child entity type

Q.122 (d) Super key can consist one or more attribute.

Q.50 (b) Q.123 (c) Shared locks can be shared by Relationship instances are called different transactions links. simultaneously. Q.124 (a) Q.112 (c) Link attribute is a relationship attribute Information at a particular moment in a data base is called instance. Q.125 (c) It is similar to Conceptual schema. Q.113 (c) An ontology is a specification of a Degree of relationship is ternary conceptualization. because relationship will keep three entity technicians, notebook and Q.126 (c) project. It is called activity diagram. Activity diagrams are graphical Q.114 (d) representation of workflows of Relation corresponding to 'N' side is stepwise activities and action. modified to include foreign key of Q.127 (d) the relation on the '1' side Implementation diagram shows the

system components inter - Q.115 (d) connection. E-R model take place in conceptual

. Q.128 (b) Q.116 (a) Set of similar entity set called entity Sub grouping is called specialization set.

Q.117 (b) Q.129 (b)

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission Primary keys are present in student SUPPLIERR table of book table only SNAME … PROJECT Q.130 (b) PRONAME … Only 2 foreign keys placed in issues PART table PARTNO … SUPPLY Q.131 (c) SNAME PRONAME PARTNO QUANTITY A multi valued dependency (MVD) X -- > > Y specified on relation schema Q.135 (b) R, where X and Y are both subsets of Three tables will be formed R, specifies the following constraint M(M1, M2, M3, P1) on any relation state r of R: If two P (Pi, P2) tuples t1 and t2 exist in r such that N (N1, N2, P1) t1[X]=t2[X], then two tuples t3 and t4 should also exist in r with the Q.137 (a) following properties, where we use Transitive functional dependencies. Z to denote (R2 (X u Y)): If all the transitive dependencies are t3 [X] = t4 [X] and t1 [X] = t2 [X] not eliminated, we may have to use t3 [Y] = t1[Y] and t4 [Y] = t2 [Y] null value to represent some of the t3 [Z] = t2 [Z] and t4 [Z] = t1[Z] possible meaningful relationships among data items, and there is the Q.132 (c) problem of repetition of information. The six basic operators of relational algebra are the selection(σ), the Q.138 (c) projection(π), the Cartesian For the given situation in the product(x) (also called the cross question, FD X→Y and Y→X will product or cross join), the set union holds together since R represents a (U), the set difference (-), and the one to one rename (p). These six operators are fundamental in the sense that none Q.140 (c) of them can be omitted without Spurious tuples are the tuples with losing expressive power. Many other null values that did not exist in the operators have been defined in original relations. terms of these six. Among the most important are set intersection, Q.141 (a) division, and the natural join, but The explanation given in the if R is aggregation is not possible with not specified then it is assumed to these basic relational algebra contain all the attributes that appear operations. So, we cannot run sum in F. of all employees' salaries with the six operations. Q.143 (d) BCNF is when all determinants are Q.133 (a) candidates key. In a one-to-many relationship, the entity that is on the one side of the Q.144 (b) relationship is called a parent entity. XY and YZ

Q.134 (b) Q.145 (a)

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission Here X, Y, Z are prime attributes. It is procedural language. Non prime attribute W depends on Y, which is not a candidate key. Q.154 (b) So, Y->W violates the definition of Query 1 and 2 will give same result 2NF. Hence, the highest normal form is 1NF Q.155 (b) It is a non - procedural language Q.146 (d). Candidates keys are X, Y, Z, W Q.156 (b) Domain relational calculus non- Q.147 (c) procedural language. NF requires data in 1NF and full functional dependent. Q.157 (c) Select statement retains duplicates Q.149 (a) where as 11 gives distinct output. a) Candidate keys: B b) C→D and C→A both cause Q.159 (a) violations of BCNF. One way to πperson name (σcompany name=FBC(works)) obtain a (lossless) join SQL: Select person_name preserving decomposition is to From works decompose R into AC, BC and CD. Where company_name = 'FBC'

Q.150 (a) Q.162 (b) a→ c Given SQL query find the sids of b →d holds so it is in INF suppliers who supply some red or ∴ It cannot be in 2 NF green parts. All the values must be atomic values that means a prime 1- value must Q.163 (a) point to only one value not a list of Sid of supplier who supply some red values. Hence, a, b, c, d include only part or at 221 packer street. atomic values only the following functioned dependencies. Q.165 (b) For the salary field of each tuple in Q.151 (d) the outer Queries of Quer 1 & When insert into 'S' operation will Query2, The Sub query in Query 1 take place there will be & Query2 outputs the number of inconsistency in the database, since salaries that are less than or equal to it has a foreign key which refers to the salary field of the tuple of the the primary key of R. When delete outer query By which query 1 gives from 'R' take place it will cause us the correct output. violation because since it's primary key is the foreign key for 'S' so there Q.166 (a) will be inconsistency in the It is a combination of date and time. database. Before deleting from R, the corresponding rows from S has Q.169 (b) to be deleted. The other option a) In transaction 1, A and B variables and d) will not cause such problems. modified and after that modification transaction 3 has read it so if we Q.152 (a) rollback transaction 1 we should

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission rollback transaction 3 also. So, it is In Conservative 2phase locking, cascading rollback schedule. transactions obtain all the locks they need before the transactions begin. Q.172 (a) CREATE INDEX ID is valid SQL for Q.185 (b) an Index If X=80 at the start (originally there were 80 reservations on the flight), Q.173 (a) N=5 (T1 transfers 5 seat HAVING clause acts like a WHERE reservations from the flight clause but is used for groups rather corresponding to X to the flight than rows. corresponding to Y), and M=4 (T2 reserves 4 seats on X), the final Q.174 (b) result should be X=79; but it is X=84 Total no of block access = because the update in T1 that BD+ [BD/(ns- 2)] * BD [in case B] removed the five seats from X was lost. It is a lost update problem. Q.175 (c) The new shared lock will be Q.189 (c) immediately granted because the Indexing→ordering of the record previous lock was also shared lock based on search key value.

Q.176 (d) Q.190 (c) The given schedule is cascade less Index→list of key, pointer to the rollback schedule. record

Q.177 (d) Q.191 (b) It is not allowed under rigorous 2PL Its main advantage is to reduce the redundant storage of search key Q.178 (c) value. Isolation makes sure concurrent transaction do not interact. Q.192 (c) In overflow block Q.179 (a) Atomicity is managed by transaction Q.193 (d) management system. n1 values 2

Q.180 (c) Q.194 (d) Isolation is managed by concurrency control component. Q.195 (a) n-Pointer with B-Tree index & each Q.183 (d) block have space for n- search key keys = {(WX),(WZ)}⇒{WX, WZ} values & n + 1 pointer X→Z,Z→Xviolates BCNF so {(XZ), (WXY)} and {(XZ), (WYZ)} Q.196 (a) BCNF decomposition Let each node of a B+ tree contains so both option A & B are correct at most n pointers and hence (n-1) after checking the lossless and keys So 8*(n-1)+12*n+56≤2048 dependency preserving conditions. so n≤100 so maximum leaf level pointers Q.184 (b) (record)=99*100*100

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission so maximum number of records that can be indexed 990000

Q.197 (c) 8 * (n-1)+12 * (2n-1)+56≤2048 so n≤62 First level of B- tree can hold 61 records pointers second level can hold at maximum 62 * 61 record pointers so leaf node have 62 * 62 * 61 record pointers, maximum number of records (indexed)= 61 + 62 * 61+62*62*61 = 238327 But if we assume that each leaf node of B- tree hold at most 99 record pointers then Maximum number of record (indexed) = 384399

Q.198 (c) Lossless, dependency preserving decomposition into BCNF is not always possible

Q.199 (a) If foo() executes sem Wait(S) and then bar() executes sem Wait(R) both processes will then block when each executes its next instruction. Since each will then be waiting for a semSignal() call from the other, neither will ever resume execution.

Q.200 (b) If either process blocks on a semWait() call then either the other process will also block as described in (a) or the other process is executing in its critical section. In the latter case, when the running process leaves its critical section, it will execute a semSignal()call, which will awaken the blocked process.

© Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission