DBMS - Unit 2
DBMS - Unit 2
1. Super key:
It is a set of one or more attributes,that taken collectively allows us identify
uniquely a tuple in the relation.
Example: Reg_no of students entity ie a superkey.
2. Primary key:
It is a candidate key which acts as a principal means of identifying tuples
within a relation.
49. What are the difference between strong entity and weak entity.
Boyce-Codd normal form (BCNF) was proposed as a simpler form of 3NF, but it
was found to be stricter than 3NF. That is, every relation in BCNF is also in 3NF;
however, a relation in 3NF is not necessarily in BCNF.
PART-B
1. Explain the Entity Relationship Model? (APRIL/MAY 2010) (nov/dec
2010) (May/June 2012)
Introduction
Basic Concepts of ERModel
o Entity
o EntitySets
o RelationshipSet
o Attributes
Constraints
o Mapping cardinalities
o Participationconstraints
o Keys
Entity Relationship Diagram –Notations
Extended E-RFeatures
o Specialization
o Generalization
o Constraints ongeneralization
o Attributeinheritance
o
Introduction:
The E-R model is a high-level data model it distinguish between basic object called
entities and relationship among those object.
Basic Concepts of ERModel
Roll no S_name
101 John
102 Peter
301 Saran
405 Michael
Types of EntitySet
o Strong EntitySet
An entity set that has a primary key is called strong entityset
o Weak EntitySet
An entity set that does not have a primary key is called
weak entityset
Attributes
An attribute of an entity set is a function that maps from the
entity set into adomain.
For each attributes, there is a set of permitted value set of that
attribute.
Types ofattributes:
Simple andcomposite
Single value andmultivalued
Derived
Descriptive
Simple & compositeattributes:
1. Simpleattributes:
Attributes that cannot be divided into subparts are called simple
attributes Ex: S.no is a simpleattributes.
2. Compositeattribute:
Attribute that can be divided into subparts is called as composite
attributes.
Ex: name -first _name, last_name
Single valued & multi valuedattribute:
1. Single valuedattribute:
The attribute that have single value for a particular entity is called
single valued attribute. Ex: student_id – refers to only one student.
2. Multivaluedattributes:
The attribute that has a set of values for a specific entity is called
multivalued attributes. Ex: phone_number.
Derived attributes:
The value of this type of attribute can be derived from the values of
otherrelated attributes orentities.
Descriptive attributes:
The attribute present in the relationship is called as descriptive attribute.
EX: 1
Dat
ee
NULL value:
The attribute takes a NULL value, when an entity does not have a value
for it.
Ex : ER diagram with composite, multivalued and derived attributes
Mapping cardinalities:
A mapping cardinality is a data constraint that specifies how many
entities an entity can be related to in a relationshipset.
Types of mapping cardinalitiesare
- one to one
- one tomany
- many toone
- many tomany
Consider a binary relationship set R on entity sets A andB.
There are four possible mapping cardinalities in thiscase:
1.One-To-One(MAY/JUNE 2013)
An entity in A is related to at most one entity in B, and an entity in B is related to
at most one entity in A.
Example: there is one project manager who manages only one project.
Project manager Handles
Project
1 1
2.One-To-Many
ComputerScience
Students * Takes 1 Course
4.Many-To-Many
An entity in A is related to any number of entities in B, but an entity in B is related
to any number of entities in A.
Example: Many teachers can teach many students
Students
Teachers teaches
Participation Constraints
1.Total Participation:
The participation of an entity set E in a relationship set R is said to be
total, if every entity in E participates in at least one relationship in R
Example :
Double Line indicate that from loan to borrower, each loan must have
atleast one associated customer
2. Partial Participation:
C_Street
Borrower Loan
Customer
name street
P-ID
city
person
salary ISA
creditrating
employee customer
Generalization:
It is a containment relationship that exists between a higher level entity set and
one or more lower level entityset.To create a generalization, the attribute must
be given in commonname.
Super class: An Entity type that represents a general concept at high level , is
called Super class.
SubClass:: An Entity type that represents a specific concept at lower levels ,is
called sub class.
person
salar IS
A creditrat
y
ing
employ custom
ee er
Constraints on generalization:
Constraint1:
Conditiondefined
Userdefined
Conditiondefined
In lower level entity sets , membership is evaluated on the basis of
whether or not an entity satisfies an explicit condition or predicate.
Entities that satisfy account type= ―saving‖, belong to low level entity
savingaccount.
Since the lower level entities are evaluated on the basics of same
attribute it is called as attribute defined.
Userdefined:
Constraint 2:
Disjoint
Overlapping
Disjoint:
A disjointness constraint requires that an entity belong to no more
one low level entityset.
Ex: Account entity satisfy only one condition either a saving account
or checking account , but cannot beboth.
Overlapping:
The same entity may belong to more than one lower level entity set
within a singlegeneralization.
Aggregation
Aggregation is a process when relation between two entities is treated
as a single entity.
Job
Manage
s
Manager
EXAMPLE : ER diagram with Aggregation
employee Branch
Work
on
Manages
Manager
Examples of ER diagrams
a. Draw an ER diagram describing theatre.
Emp_id Emp_name
AS555 Harry
AS811 George
AS999 Kevin
Consider this table with two columns Emp_id and Emp_name.
{Emp_id, Emp_name} -> Emp_id is a trivial functional dependency as Emp_id is a
subset of {Emp_id,Emp_name}.
Example:
(Company} -> {CEO} (if we know the Company, we knows the CEO name)But CEO is
not a subset of Company, and hence it's non-trivial functional dependency.
Transitive dependency:
A transitive is a type of functional dependency which happens when t is indirectly
formed by two functional dependencies.
Example:
Alibaba Jack Ma 54
{Company} -> {CEO} (if we know the compay, we know its CEO's name)
{CEO } -> {Age} If we know the CEO, we know the Age
Therefore according to the rule of rule of transitive dependency:
{ Company} -> {Age} should hold, that makes sense because if we know the company
name, we can know his age.
A B C
1 2 1
2 5 3
3 3 3
R( A , B , C )
Consider this relation is decomposed into two sub relations R1( A , B ) and R2( B , C )-
A B
1 2
2 5
3 3
R1( A , B )
B C
2 1
5 3
R2( B , C )
A B C
1 2 1
2 5 3
3 3 3
This relation is same as the original relation R.Thus, we conclude that the above
decomposition is lossless join decomposition.
2.Dependency Preservation
Dependency is an important constraint on the database.
Every dependency must be satisfied by at least one decomposed table.
If {A → B} holds, then two sets are functional dependent. And, it becomes more
useful for checking the dependency easily if both sets in a same relation.
This decomposition property can only be done by maintaining the functional
dependency.
In this property, it allows to check the updates without computing the natural join of
the database structure.
It is the process of eliminating duplicate forms from same data and creating the
separate tables for each group of related data and also to identify each row with
a unique column or set of columns.
The table has repeating groups; it is called an unnormalized table.
Relational databases require that each row only has a single value per
attribute, and so a repeating group in a row is not allowed.
A relation is in first normal form if it meets the definition of a relation:
1. Each attribute (column) value must be a single value only.
2. All values for a given attribute (column ) must be of the same type.
3. Each attribute (column) name must be unique.
4. No two tuples (rows) in a relation can be identical.
o Example:
Summary: 1NF
A relation is in 1NF if it contains no repeating groups
To convert an unnormalised relation to 1NF either
A relation is in 2NF if and only if, it is in 1NF and every non-key attribute is
fully functionally dependent on the whole key (primary key). i.e. All attributes
are fully dependent on primary key.
A relation is in second normal form (2NF) if its non-prime attributes are fully
functionally dependent on primary key.
TEACHER table
25 Chemistry 30
25 Biology 30
47 English 35
83 Math 38
83 Computer 38
To convert the given table into 2NF, we decompose it into two tables:
TEACHER_DETAIL table:
TEACHER_ID TEACHER_AGE
25 30
83 38
TEACHER_SUBJECT table:
TEACHER_ID SUBJECT
25 Chemistry
25 Biology
47 English
83 Math
83 Computer
Summary: 2NF
A relation is in 2NF if it contains no repeating groups and no partial key
functional dependencies.
Rule: A relation in 1NF with a single key field must be in 2NF
To convert a relation with partial functional dependencies to 2NF. Create a set
of new relation.
One relation for the attributes that are fully dependent upon the key
One relation for each part of the key that has partially dependent attributes.
9 Explain Third Normal Form (3 NF) with a suitable Example? (MAY/JUNE 2012)
Third Normal Form
the third normal form let us first discuss the concept transitive dependency, super
key and candidate key .
X->Y
Y->Z
Concept of Super key and Candidate Key
Superkey : A super key is a set or one of more columns (attributes) to unique identify
rows in a table.
Candidate key: The minimal set of attribute which can uniquely identify a
tupleknown as candidate key. For example consider following table
101 1 AAA
102 2 BBB
103 3 CCC
104 4 DDD
Superkeys
{RegID}
{RegID, RollNo}
{RegID,Sname}
{RollNo,Sname}
{RegID, RollNo,Sname}
Candidate Keys
{RegID}
{RollNo}
Third Normal Form
A table is said to be in the Third Normal Form when,
i) It is in the Second Normal form.(i.e. it does not have partial functional
dependency
ii) It doesn't have transitive dependency.
Or in other words
In other words 3NF can be defined as : A table is in 3NF if it is in 2NF and for each
Summary: 3NF
A relation is in 3NF if it contains no repeating groups, no partial functional
dependencies, and no transitive functional dependencies.
T converts a relation with transitive functional dependencies to 3NF, remove
the attributes involved in the transitive dependency and put them in a new
relation.
Rule: A relation in 2NF with only one non-key attribute must be in 3NF
In a normalized relation a non-key field must provide a fact about the key, the
whole key and nothing but the key.
Relations in 3NF are sufficient for most practical database design problems.
However, 3NF does not guarantee that all anomalies have been removed.
10. Explain Boyce/Codd Normal Form (BCNF) with a suitable Example?
(MAY/JUNE 2012)
Boyce/Codd Normal Form (BCNF)
Boyce and Codd Normal Form is a higher version of the Third Normal form.
This formdeals with certain type of anomaly that is not handled by 3NF.
A 3NF table which does not have multiple overlapping candidate keys is said
to be in BCNF.
For a table to be in BCNF, following conditions must be satisfied:
i) R must be in 3rd Nohnal Form
ii) For each functional dependency ( X ~ Y ), X should be a super Key. In simple
words if Y is a prime attribute then X can not be non prime attribute.
For example - Consider following table that represents that a Student
enrollment for the course-
Enrollment Table
sid Teacher
1 Ankita
1 Poonam
2 Ankita
3 Supriya
4 Archana
Course
Here sid =1 leads to multiple values for courses and skill. Following table shows
this
1 C English
1 C++ German
1 C German
1 C++ English
2 Java English
2 Java French
Here sid and course are dependent but the Course and Skill are
independent.the multivalued dependency is denoted as :
sid >Course
sid > Skill
Fourth Normal Form
Definition: For a table to satisfy the Fourth Normal Form, it should satisfy the
following two conditions :
1) It should be in the Boyce-Codd Normal Form(BCNF).
2) And, the table should not have any multi-valued dependency.
For example: Consider following student relation which is not in 4NF as it cont '
multivalued dependency.
Student Table
sid Course
1 C
1 C++
2 Java
Student_skill table:
Key : (sid,skill)
sid Skill
1 English
1 German
2 English
2 French
Thus the table in in 4 th
normal form.
12. Explain Join Dependency and Fifth Normal Form (5 NF)? (MAY/JUNE 2013)
Join Dependency and Fifth Normal Form (5NF)
The fifth normal form is also called as project join normal form.
For example - Consider following table
Seller Company Product
Rupali Godrej Cinthol
Sharda Dabur Honey
Seller Company
Rupali Godrej
Sharda Dabur
Sunil Amul
Sunil Britania
Seller_product
Seller Product
Rupali Cinthol
Sharda Honey
Sharda HairOil
Sharda RoseWater
Sunil Icecream
Sunil . Biscuits
To avoid the above problem we can decompose the tables into three tables as
Seller Company, Seller_Product, and Company Product table
Seller , Company
Seller Company
Rupali Godrej
Sharda Dabur
Sunil Amul
Sunil Britania
Seller_Product
Seller Product
Rupali Cinthol
Sharda Honey
Sharda HairOil
Sharda RoseWater
Sunil Icecream
Sunil Biscuit
Company_Product
Company Product
Godrej Cinthol
Dabur Honey
Dabur HairOil
Dabur RoseWater
Amul Icecream
Britania Biscuit
Mapping Entity
An entity is a real-world object with some attributes.
Mapping Relationship
A relationship is an association among entities.
Mapping Process
Mapping Process
Mapping Process
Create tables for all higher-level entities.
Create tables for lower-level entities.
Add primary keys of higher-level entities in the table of lower-level entities.
In lower-level tables, add all other attributes of lower-level entities.
Declare primary key of higher-level table and the primary key for lower-level
table.
Declare foreign key constraints.
APRIL MAY-2019
PART-A
1.a) What is normalization? Explain in detail about all normal forms? Pg-38,Qn-6
to 12
b) Briefly discuss about the functional dependency Concept? Pg-34 ,Qn-4
NOVEMBER/DECEMBER 2019
PART-A