VTU Exam Question Paper With Solution of 15CS53 Database Management System Dec-2017-Swetha K V
VTU Exam Question Paper With Solution of 15CS53 Database Management System Dec-2017-Swetha K V
MODULE 1
1 a.
1 b.
2a. Attribute—the particular properties that describe an entity. For example, an EMPLOYEE entity may be
described by the employee’s name, age, address, salary, and job.
Several types of attributes occur in the ER model: simple versus composite, singlevalued versus
multivalued, and stored versus derived.
Composite versus Simple (Atomic) Attributes: Composite attributes can be divided into smaller subparts,
which represent more basic attributes with independent meanings. For example, the Address attribute of the
EMPLOYEE entity can be subdivided into Street_address, City, State, and Zip,3 with the values ‘2311
Kirby’, ‘Houston’, ‘Texas’, and ‘77001.’ Attributes that are not divisible are called simple or atomic
attributes. Composite attributes can form a hierarchy; for example, Street_address can be further subdivided
into three simple component attributes: Number, Street, and Apartment_number,
Single-Valued versus Multivalued Attributes: Most attributes have a single value for a particular entity;
such attributes are called single-valued. For example, Age is a single-valued attribute of a person.
one person may not have a college degree, another person may have one, and a third person may have two
or more degrees; therefore, different people can have different numbers of values for the College_degrees
attribute. Such attributes are called multivalued. A multivalued attribute may have lower and upper bounds
to constrain the number of values allowed for each individual entity.
Stored versus Derived Attributes: In some cases, two (or more) attribute values are related—for example,
the Age and Birth_date attributes of a person. For a particular person entity, the value of Age can be
determined from the current (today’s) date and the value of that person’s Birth_date. The Age attribute is
hence called a derived attribute and is said to be derivable from the Birth_date attribute, which is called a
stored attribute.
2b.
MODULE 2
3a. Ordering of Tuples: A relation is a set of tuples; hence, there is no order associated with them. That is, it
makes no sense to refer to, for example, the 5th tuple in a relation. When a relation is depicted as a table, the
tuples are necessarily listed in some order, of course, but you should attach no significance to that order.
Similarly, when tuples are represented on a storage device, they must be organized in some fashion, and it
may be advantageous, from a performance standpoint, to organize them in a way that depends upon their
content.
Ordering of Attributes: A tuple is best viewed as a mapping from its attributes (i.e., the names we give to
the roles played by the values comprising the tuple) to the corresponding values. Hence, the order in which
the attributes are listed in a table is irrelevant.
The Null value: used for don't know, not applicable.
Interpretation of a Relation: Each relation can be viewed as a predicate and each tuple in that relation
can be viewed as an assertion for which that predicate is satisfied (i.e., has value true) for the combination
of values in it. In other words, each tuple represents a fact. Example (see Figure 5.1): The first tuple listed
means: There exists a student having name Benjamin Bayer, having SSN 305-61-2435, having age 19, etc.
Keep in mind that some relations represent facts about entities (e.g., students) whereas others represent facts
about relationships (between entities). (e.g., students and course sections).The closed world assumption
states that the only true facts about the miniworld are those represented by whatever tuples currently
populate the database.
3 b.
4 a. Step 1: For each regular (strong) entity type E in the ER schema, create a relation R that includes all the
simple attributes of E.
Step 2: For each regular (strong) entity type E in the ER schema, create a relation R that includes all the
simple attributes of E.
Step 3: For each binary 1:1 relationship type R in the ER schema, identify the relations S and T that
correspond to the entity types participating in R. Choose one of the relations, say S, and include the primary
key of T as a foreign key in S. Include all the simple attributes of R as attributes of S.
Step 4: For each regular binary 1:N relationship type R identify the relation (N) relation S. Include the
primary key of T as a foreign key of S. Simple attributes of R map to attributes of S.
Step 5: For each binary M:N relationship type R, create a relation S. Include the primary keys of
participant relations as foreign keys in S. Their combination will be the primary key for S. Simple attributes
of R become attributes of S.
Step 6: For each multi-valued attribute A, create a new relation R. This relation will include an attribute
corresponding to A, plus the primary key K of the parent relation (entity type or relationship type) as a
foreign key in R. The primary key of R is the combination of A and K.
Step 7: For each n-ary relationship type R, where n>2, create a new relation S to represent R. Include the
primary keys of the relations participating in R as foreign keys in S. Simple attributes of R map to attributes
of S. The primary key of S is a combination of all the foreign keys that reference the participants that have
cardinality constraint > 1.
Not Null: By default, a column can hold NULL values. If you do not want a column to have a NULL value,
then you need to define such constraint on this column specifying that NULL is now not allowed for that
column.
Unique: The UNIQUE Constraint prevents two records from having identical values in a particular column.
Default: The DEFAULT constraint provides a default value to a column when the INSERT INTO statement
does not provide a specific value.
Primary Key: A primary key is a single field or combination of fields that uniquely identify a record. The
fields that are part of the primary key cannot contain a NULL value and must be Unique. Each table should
have a primary key, and each table can have only ONE primary key.
Foreign Key: A foreign key is a key used to link two tables together. Foreign Key is a column or a
combination of columns whose values match a Primary Key of another table. The relationship between 2
tables matches the Primary Key in one of the tables with a Foreign Key in the second table.
Example:
CREATE TABLE EMPLOYEE
(
SSN NUMBER(10) PRIMARY KEY,
NAME VARCHAR(10) NOT NULL,
PHONE NUMBER(10) UNIQUE,
AGE NUMBER(2) CHECK AGE>16,
SALARY NUMBER(5) DEFAULT 10000,
DEPTNO NUMBER(2) REFERENCES DEPARTMENT(DNO)
)
MODULE 3
5a. STAFFORD_PROJS ← σPlocation=‘Stafford’(PROJECT)
CONTR_DEPTS ← (STAFFORD_PROJS Dnum=DnumberDEPARTMENT)
PROJ_DEPT_MGRS ← (CONTR_DEPTS Mgr_ssn=SsnEMPLOYEE)
RESULT ← πPnumber, Dnum, Lname, Address, Bdate(PROJ_DEPT_MGRS)
5b.
5c.
accessed it through dumb teT'minals that could perform only data input and display. This approach ha..s the
benefit of being easily maintained by a central administrator.
Single-tier architectures have a,n important drawback: Users expect graphical interfaces that require much
more computational power than simple dumb terminals. Centralized computation of the graphical displays
of such interfaces requires much more computational power than a single server hclS available, and thus
single-tier architectures do not scale to thousands of users. The commoditization of the PC and the
availability of cheap client computers led to the developlnent of the two-tier architecture. Two-tier
architectures, often also referred to a<; client-server architectures, consist of a client computer and a server
computer, which interact through a well-defined protocol. What part of the functionality the client
implements, and what part is left to the server, can vary. In the traditional clientserver architecture, the client
implements just the graphical user interface, and the server. implements both the business logic and the data
management; such clients are often called thin clients, and this architecture is illustra,ted in Figure 7.6
Compared to the single-tier architecture, two-tier architectures physically separate the user interface from
the data management layer. To implement twotier architectures, we can no longer have dumb terminals on
the client side; we require computers that run sophisticated presentation code (and possibly, application
logic).
MODULE 4
7a. GUIDELINE 1: Design a relation schema so that it is easy to explain its meaning. Do not combine attributes
from multiple entity types and relationship types into a single relation. Intuitively, if a relation schema
corresponds to one entity type or one relationship type, the meaning tends to be clear.
GUIDELINE 2: Design the base relation schemas so that no insertion, deletion, or modification anomalies
are present in the relations. If any anomalies are present, note them clearly and make sure that the programs
that update the database will operate correctly.
GUIDELINE 3: As far as possible, avoid placing attributes in a base relation whose values may frequently
be null. If nulls are unavoidable, make sure that they apply in exceptional cases only and do not apply to a
majority of tuples in the relation.
Having too many Null values can be waste space at the storage level and may also lead to problems with
understanding the meaning of the attributes and with specifying JOIN operations at the logical level.
Another problem with nulls is how to account for them when aggregate operations such as COUNT or SUM
are applied. Moreover, nulls can have multiple interpretations.
GUIDELINE 4: Design relation schemas so that they can be JOINed with equality conditions on attributes
that are either primary keys or foreign keys in a way that guarantees that no spurious tuples are generated.
Do not have relations that contain matching attributes other than foreign key-primary key combinations. If
such relations are unavoidable, do not join them on such attributes, because the join may produce spurious
tuples.
7b. Normalization:
The process of decomposing unsatisfactory "bad" relations by breaking up their attributes
into smaller relations
Normal form:
Condition using keys and FDs of a relation to certify whether a relation schema is in a
particular normal form
MODULE 5
9a. Several problems can occur when concurrent transactions execute in an uncontrolled manner.
Consider two transactions below:
9b. Transactions should possess several properties, often called the ACID properties
The following are the ACID properties:
■ Atomicity. A transaction is an atomic unit of processing; it should either be performed in its entirety or
not performed at all.
■ Consistency preservation. A transaction should be consistency preserving, meaning that if it is
completely executed from beginning to end without interference from other transactions, it should take the
database from one consistent state to another.
■ Isolation. A transaction should appear as though it is being executed in isolation from other transactions,
even though many transactions are executing concurrently. That is, the execution of a transaction should
not be interfered with by any other transactions executing concurrently.
■ Durability or permanency. The changes applied to the database by a committed transaction must persist
in the database. These changes must not be lost because of any failure.
10a. Deadlock occurs when each transaction T in a set of two or more transactions is waiting for some item that
is locked by some other transaction T′ in the set. Hence, each transaction in the set is in a waiting queue,
waiting for one of the other transactions in the set to release the lock on an item.
Deadlock Prevention Protocols:
One way to prevent deadlock is to use a deadlock-prevention protocol.
One deadlock prevention protocol, which is used in conservative two-phase locking, requires that every
transaction lock all the items it needs in advance.
A second protocol, which also limits concurrency, involves ordering all the items in the database and
making sure that a transaction that needs several items will lock them according to that order.
Some of these techniques use the concept of transaction timestamp TS(T), which is a unique identifier
assigned to each transaction.
Two schemes that prevent deadlock are called wait-die and wound-wait.
Wait-die. If TS(Ti) < TS(Tj), then (Ti older than Tj) Ti is allowed to wait; otherwise (Ti younger than Tj)
abort Ti (Ti dies) and restart it later with the same timestamp.
■ Wound-wait. If TS(Ti) < TS(Tj), then (Ti older than Tj) abort Tj (Ti wounds Tj) and restart it later with
the same timestamp; otherwise (Ti younger than Tj) Ti is allowed to wait.
In wait-die, an older transaction is allowed to wait for a younger transaction, whereas a younger transaction
requesting an item held by an older transaction is aborted and restarted. Wound-wait does the opposite.
Another group of protocols that prevent deadlock do not require timestamps. These include the no waiting
(NW) and cautious waiting (CW) algorithms. In the no waiting algorithm, if a transaction is unable to
obtain a lock, it is immediately aborted and then restarted after a certain time delay without checking
whether a deadlock will actually occur or not. Suppose that transaction Ti tries to lock an item X but is not
able to do so because X is locked by some other transaction Tj with a conflicting lock. The cautious waiting
rule is as follows: Cautious waiting: If Tj is not blocked (not waiting for some other locked item), then Ti is
blocked and allowed to wait; otherwise abort Ti.
Deadlock Detection:
A simple way to detect a state of deadlock is for the system to construct and maintain a wait-for graph. One
node is created in the wait-for graph for each transaction that is currently executing. Whenever a transaction
Ti is waiting to lock an item X that is currently locked by a transaction Tj, a directed edge (Ti -> Tj) is
created in the wait-for graph. When Tj releases the lock(s) on the items that Ti was waiting for, the directed
edge is dropped from the wait-for graph. We have a state of deadlock if and only if the wait-for graph has a
cycle. Another simple scheme to deal with deadlock is the use of timeouts. In this method, if a transaction
waits for a period longer than a system-defined timeout period, the system assumes that the transaction may
be deadlocked and aborts it.
Starvation:
Starvation occurs when a particular transaction consistently waits or restarted and never gets a chance to
proceed further.
In a deadlock resolution it is possible that the same transaction may consistently be selected as victim and
rolled-back.
This limitation is inherent in all priority based scheduling mechanisms.
In Wound-Wait scheme a younger transaction may always be wounded (aborted) by a long running older
transaction which may create starvation.
10b. Shadow paging considers the database to be made up of a number of fixed size disk pages (or disk blocks)—
say, n—for recovery purposes. A directory with n entries is constructed, where the ith entry points to the ith
database page on disk.
The directory is kept in main memory if it is not too large, and all references—reads or writes—to database
pages on disk go through it. When a transaction begins executing, the current directory—whose entries
point to the most recent or current database pages on disk—is copied into a shadow directory. The shadow
directory is then saved on disk while the current directory is used by the transaction.
During transaction execution, the shadow directory is never modified. When a write_item operation is
performed, a new copy of the modified database page is created, but the old copy of that page is not
overwritten. Instead, the new page is written elsewhere—on some previously unused disk block. The current
directory entry is modified to point to the new disk block, whereas the shadow directory is not modified and
continues to point to the old unmodified disk block.