Professional Documents
Culture Documents
Cat2 DBDM Key
Cat2 DBDM Key
Cat2 DBDM Key
Functional dependency is a relationship that exists when one attribute uniquely determines another
attribute. It R is a relation with attributes X and Y, a functional dependency between the attributes is
represented as X->Y, which specifies Y is functionally dependent on X. Functional Dependecny (FD) is a
set of constraints between two attributes in a relation.
2. What is decomposition?
We claim the above decomposition is lossless. How can we decide whether decomposition is lossless? 1.
Let R be a relation schema. 2. Let F be a set of functional dependencies on R. 3. Let R1and R2 form a
decomposition of R. 4. The decomposition is a lossless-join decomposition of R if at least one of the
following functional dependencies are in : a. R1∩ R2→ R1 b. b. R1∩ R2→ R2
Weak entity set: entity set that do not have key attribute of their own are called weak entity sets. Strong
entity set: Entity set that has a primary key is termed a strong entity set.
1NF databases have some problems: Most notable: repetition of data to change a department name all
tuples of the relation need to be updated since the department name can exist in multiple rows.
A relation schema R is in 2NF if it is in 1NF and every non-prime attribute A in R is fully functionally
dependent on primary key.00
Collections of operations that form a single logical unit of work are Called transactions.
To process transactions concurrently, the database server must execute some Component statements of
one transaction, then some from other Transactions, before continuing to process further operations
from the first. The order in which the component operations of the various transactions are Interleaved
is called the schedule.
: Find the address of disk block that contain item x. Copy that disk block into buffer in main memory.
Copy item x from the program variable named x into its correct location In the buffer Store the update
block from the buffer back to disk.
A transaction is said to follow the Two-Phase Locking protocol if Locking and Unlocking can be
done in two phases.
Growing Phase: New locks on data items may be acquired but none can be released.
Shrinking Phase: Existing locks may be released but no new locks can be acquired.
PART – B
11. a) Discuss in details the steps involved in the ER to Relational – Relational mapping
Mapping Entity
Mapping Relationship
Mapping Process
A weak entity set is one which does not have any primary key associated with it.
Mapping Process
Mapping Process
Lossless Decomposition
Decomposition is lossless if it is feasible to reconstruct relation R from decomposed tables using
Joins. This is the preferred choice. The information will not lose from the relation when
decomposed. The join would result in the same original relation.
<EmpInfo>
<EmpDetails>
Lossy Decomposition
As the name suggests, when a relation is decomposed into two or more relational schemas, the
loss of information is unavoidable when the original relation is retrieved.
<EmpInfo>
<EmpDetails>
Dept_ID Dept_Name
Dpt1 Operations
Dpt2 HR
Dpt3 Finance
Now, you won’t be able to join the above tables, since Emp_ID isn’t part of
the DeptDetails relation.
Therefore, the above relation has lossy decomposition.
The relational database design algorithms that we present in Section 16.3 start from a
single universal relation schema R = {A1, A2, ..., An} that includes all the attributes of the
database. We implicitly make the universal relation assumption, which states that every
attribute name is unique. The set F of functional dependencies that should hold on the attributes
of R is specified by the database designers and is made available to the design algorithms. Using
the functional dependencies, the algorithms decompose the universal relation schema R into a set
of relation schemas D = {R1, R2, ..., Rm} that will become the relational database schema; D is
called a decomposition of R.
We must make sure that each attribute in R will appear in at least one relation schema Ri in the
decomposition so that no attributes are lost; formally, we have
Another goal is to have each individual relation Ri in the decomposition D be in BCNF or 3NF.
However, this condition is not sufficient to guarantee a good data-base design on its own. We
must consider the decomposition of the universal rela-tion as a whole, in addition to looking at
the individual relations. To illustrate this point, consider the EMP_LOCS(Ename, Plocation)
relation in which is in 3NF and also in BCNF. In fact, any relation schema with only two
attributes is auto-matically in BCNF.5 Although EMP_LOCS is in BCNF, it still gives rise to
spurious tuples when joined with EMP_PROJ (Ssn, Pnumber, Hours, Pname, Plocation), which
is not in BCNF (see the result of the natural join in Figure 15.6). Hence, EMP_LOCS represents
a particularly bad relation schema because of its convoluted semantics by which Plocation gives
the location of one of the projects on which an employee works.
Joining EMP_LOCS with PROJECT(Pname, Pnumber, Plocation, Dnum) in which is in
BCNF—using Plocation as a joining attribute also gives rise to spurious tuples. This underscores
the need for other criteria that, together with the conditions of 3NF or BCNF, prevent such bad
designs. In the next three subsections we discuss such additional conditions that should hold on a
decomposition D as a whole.
12. b) Define normalization? Explain 1NF, 2NF, 3NF normal forms.
First Normal Form
If a relation contain composite or multi-valued attribute, it violates first normal form or a relation is in
first normal form if it does not contain any composite or multi-valued attribute. A relation is in first
normal form if every attribute in that relation is singled valued attribute.
Example 1 – Relation STUDENT in table 1 is not in 1NF because of multi-valued attribute
STUD_PHONE. Its decomposition into 1NF has been shown in table 2.
Example
Example 2 –
ID Name Courses
------------------
1 A c1, c2
2 E c3
3 M C2, c3
In the above table Course is a multi-valued attribute so it is not in 1NF. Below Table is in 1NF as
there is no multi-valued attribute
ID Name Course
------------------
1 A c1
1 A c2
2 E c3
3 M c2
3 M c3
Second Normal Form
To be in second normal form, a relation must be in first normal form and relation must not contain any
partial dependency. A relation is in 2NF if it has No Partial Dependency, i.e., no non-prime attribute
(attributes which are not part of any candidate key) is dependent on any proper subset of any candidate
key of the table. Partial Dependency – If the proper subset of candidate key determines non-prime
attribute, it is called partial dependency.
Example 1 – Consider table-3 as following below.
STUD_NO COURSE_NO COURSE_FEE
1 C1 1000
2 C2 1500
1 C4 2000
4 C3 1000
4 C1 1000
2 C5 2000
{Note that, there are many courses having the same course fee} Here, COURSE_FEE cannot alone
decide the value of COURSE_NO or STUD_NO; COURSE_FEE together with STUD_NO cannot
decide the value of COURSE_NO; COURSE_FEE together with COURSE_NO cannot decide the
value of STUD_NO; Hence, COURSE_FEE would be a non-prime attribute, as it does not belong to
the one only candidate key {STUD_NO, COURSE_NO} ; But, COURSE_NO -> COURSE_FEE,
i.e., COURSE_FEE is dependent on COURSE_NO, which is a proper subset of the candidate key.
Non-prime attribute COURSE_FEE is dependent on a proper subset of the candidate key, which is a
partial dependency and so this relation is not in 2NF. To convert the above relation to 2NF, we need
to split the table into two tables such as : Table 1: STUD_NO, COURSE_NO Table 2:
COURSE_NO, COURSE_FEE
Table 1 Table 2
STUD_NO COURSE_NO COURSE_NO COURSE_FEE
1 C1 C1 1000
2 C2 C2 1500
1 C4 C3 1000
4 C3 C4 2000
4 C1 C5 2000
NOTE: 2NF tries to reduce the redundant data getting stored in memory. For instance, if there are
100 students taking C1 course, we don’t need to store its Fee as 1000 for all the 100 records,
instead, once we can store it in the second table as the course fee for C1 is 1000.
Example 2 – Consider following functional dependencies in relation R (A, B , C, D )
AB -> C [A and B together determine C]
BC -> D [B and C together determine D]
In the above relation, AB is the only candidate key and there is no partial dependency, i.e., any proper
subset of AB doesn’t determine any non-prime attribute.
X is a super key.
Y is a prime attribute (each element of Y is part of some candidate key).
Example 1: In relation STUDENT given in Table 4, FD set: {STUD_NO -> STUD_NAME,
STUD_NO -> STUD_STATE, STUD_STATE -> STUD_COUNTRY, STUD_NO -> STUD_AGE}
Candidate Key: {STUD_NO}
For this relation in table 4, STUD_NO -> STUD_STATE and STUD_STATE -> STUD_COUNTRY
are true.
So STUD_COUNTRY is transitively dependent on STUD_NO. It violates the third normal form.
To convert it in third normal form, we will decompose the relation STUDENT (STUD_NO,
STUD_NAME, STUD_PHONE, STUD_STATE, STUD_COUNTRY_STUD_AGE) as: STUDENT
(STUD_NO, STUD_NAME, STUD_PHONE, STUD_STATE, STUD_AGE) STATE_COUNTRY
(STATE, COUNTRY)
Consider relation R(A, B, C, D, E) A -> BC, CD -> E, B -> D, E -> A All possible candidate keys in
above relation are {A, E, CD, BC} All attributes are on right sides of all functional dependencies are
prime.
Example 2: Find the highest normal form of a relation R(A,B,C,D,E) with FD set as {BC->D, AC-
>BE, B->E}
Step 1: As we can see, (AC)+ ={A,C,B,E,D} but none of its subset can determine all attribute of
relation, So AC will be candidate key. A or C can’t be derived from any other attribute of the relation,
so there will be only 1 candidate key {AC}.
Step 2: Prime attributes are those attributes that are part of candidate key {A, C} in this example and
others will be non-prime {B, D, E} in this example.
Step 3: The relation R is in 1st normal form as a relational DBMS does not allow multi-valued or
composite attribute. The relation is in 2nd normal form because BC->D is in 2nd normal form (BC is
not a proper subset of candidate key AC) and AC->BE is in 2nd normal form (AC is candidate key) and
B->E is in 2nd normal form (B is not a proper subset of candidate key AC).
The relation is not in 3rd normal form because in BC->D (neither BC is a super key nor D is a prime
attribute) and in B->E (neither B is a super key nor E is a prime attribute) but to satisfy 3rd normal for,
either LHS of an FD should be super key or RHS should be prime attribute. So the highest normal form
of relation will be 2nd Normal form.
For example consider relation R(A, B, C) A -> BC, B -> A and B both are super keys so above relation
is in BCNF.
Third Normal Form
A relation is said to be in third normal form, if we did not have any transitive dependency for non-
prime attributes. The basic condition with the Third Normal Form is that, the relation must be in
Second Normal Form.
Below mentioned is the basic condition that must be hold in the non-trivial functional dependency X ->
Y:
X is a Super Key.
Y is a Prime Attribute ( this means that element of Y is some part of Candidate Key).
For more, refer to Third Normal Form in DBMS.
13.a) Compare and contrast Boyce Code Normal Form(BCNF )with 3NF?
3NF
There shouldn’t be any transitive dependency.
There shouldn’t be any non-prime attribute that depends transitively on a candidate key.
It is easy to achieve.
BCNF
For any relation A->B, ‘A’ should be a super key of that specific relation.
It is difficult to achieve.
ACID Properties
A transaction is a very small unit of a program and it may contain several lowlevel tasks. A
transaction in a database system must maintain Atomicity, Consistency, Isolation, and Durability
− commonly known as ACID properties − in order to ensure accuracy, completeness, and data
integrity.
Atomicity − This property states that a transaction must be treated as an atomic unit, that
is, either all of its operations are executed or none. There must be no state in a database
where a transaction is left partially completed. States should be defined either before the
execution of the transaction or after the execution/abortion/failure of the transaction.
Consistency − The database must remain in a consistent state after any transaction. No
transaction should have any adverse effect on the data residing in the database. If the
database was in a consistent state before the execution of a transaction, it must remain
consistent after the execution of the transaction as well.
Durability − The database should be durable enough to hold all its latest updates even if
the system fails or restarts. If a transaction updates a chunk of data in a database and
commits, then the database will hold the modified data. If a transaction commits but the
system fails before the data could be written on to the disk, then that data will be updated
once the system springs back into action.
Isolation − In a database system where more than one transaction are being executed
simultaneously and in parallel, the property of isolation states that all the transactions will
be carried out and executed as if it is the only transaction in the system. No transaction
will affect the existence of any other transaction.
15.b)Discuss two phase locking protocol and strict two phase locking protocols
Locking and unlocking of the database should be done in such a way that there is no
inconsistency, deadlock, and no starvation.
Types
Two phase locking is of two types −
Example
Let T1 and T2 are two transactions.
T1=A+B and T2=B+A
T1 T2
T1 T2
Lock-X(A) Lock-X(B)
Read A; Read B;
Lock-X(B) Lock-X(A)
Here,
Lock-X(B) : Cannot execute Lock-X(B) since B is locked by T2.
Lock-X(A) : Cannot execute Lock-X(A) since A is locked by T1.
In the above situation T1 waits for B and T2 waits for A. The waiting time never ends. Both the
transaction cannot proceed further at least any one releases the lock voluntarily. This situation is
called deadlock.
The wait for graph is as follows −
Wait for graph: It is used in the deadlock detection method, creating a node for each transaction,
creating an edge Ti to Tj, if Ti is waiting to lock an item locked by Tj. A cycle in WFG indicates a
deadlock has occurred. WFG is created at regular intervals.
15.a)Check whether the following schedule is conflict serializable or not conflict serializable then
find the serializability order
T1 T2 T3
R(A)
R(B)
R(B)
W(B)
W(A)
W(A)
R(A)
W(A)
Soln:
T1:read(A)
Read(B);
If A=0 then B=B+1;
T2:read(B);
read(A) If B=0 then A=A+1
Write(A)
Add lock and unlock instructions to transactions T1 and T2, so that they observe two phase locking
protocol. Can the execution of these transactions result in deadlock?
Soln:
16.a) A software contract and consultancy firm maintains details of all various projects in which
its employees are currently involved. These details comprise
1.Employee number
2.Employee name
3.Date of Birth
4.Department code
5. Department Name
6.Project code
7.Project description
8.Project Supervisor
Assume the following :
Each Employee number is unique
Each department has a single department code
Each project has a single code and supervisor
Each employee may work on one or more projects
Employee names need not necessarily be unique
Project code, project description and project supervisor are repeating fields.
Normalise this data to third normal form
16.b) Draw E-R Diagram for the Restaurant menu ordering system that will facilitate the food items
ordering and services with in a restaurant.