Unit-2 DBMS Notes
Unit-2 DBMS Notes
The logical model concentrates on the data requirements and the data
to be stored independent of physical considerations. It does not
concern itself with how the data will be stored or where it will be
stored physically.
What is ER Diagram?
ER Diagram stands for Entity Relationship Diagram, also known as ERD
is a diagram that displays the relationship of entity sets stored in a
database. In other words, ER diagrams help to explain the logical
structure of databases. ER diagrams are created based on three basic
concepts: entities, attributes and relationships.
ER Diagram Symbols
• Entities
• Attributes
• Relationships
ER Diagram Examples
Examples of entities:
Notation of an Entity
Entity set:
Student
Relationship
Relationship is nothing but an association among two or more entities.
E.g., Tom works in the Chemistry department.
Weak Entities
A weak entity is a type of entity which doesn’t have its key attribute. It
can be identified uniquely by considering the primary key of another
entity. For that, weak entity sets need to have participation.
Strong entity set always has a It does not have enough attributes
primary key. to build a primary key.
The member of a strong entity set is The member of a weak entity set
called as dominant entity set. called as a subordinate entity set.
Cardinality
Defines the numerical attributes of the relationship between two
entities or entity sets.
• One-to-One Relationships
• One-to-Many Relationships
• May to One Relationships
• Many-to-Many Relationships
1.One-to-one:
One entity from entity set X can be associated with at most one entity
of entity set Y and vice versa.
Example: One student can register for numerous courses. However, all
those courses have a single line back to that one student.
2.One-to-many:
One entity from entity set X can be associated with multiple entities of
entity set Y, but an entity from entity set Y can be associated with at
least one entity.
3. Many to One
More than one entity from entity set X can be associated with at most
one entity of entity set Y. However, an entity from entity set Y may or
may not be associated with more than one entity from entity set X.
One-to-many relationship
An entity set A is associated with any number of entities in B with a
possibility of zero and an entity in B is associated with at most one
entity in A.
Many-to-one relationship
An entity set A is associated with at most one entity in B and an entity
set in B can be associated with any number of entities in A with a
possibility of zero.
Many-to-many relationship
An entity set A is associated with any number of entities in B with a
possibility of zero and an entity in B is associated with any number of
entities in A with a possibility of zero.
Participation Constraints
Participate constraints are two types as mentioned below −
• Total participation
• Partial Participation
The participation constraints are explained in the diagram below −
Here, the customer to Loan is partial participation and the loan to the
customer is total participation.
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.
For Example − Participation of loan in the relationship borrower is total
participation.
Partial Participation
If only some of the entities in E participate in relationship R, then the
participation of E in R is said to be partial participation.
For example − Participation of customers in the relationship borrower is
partial participation.
Reduction of schemas to relational schemas
Entity-Relationship (ER) Diagram is a diagrammatic representation of
data in databases, it shows how data is related.
Note: This article is for those who already know what is ER diagram
and how to draw ER diagram.
1) When there are Many to One cardinalities in the ER diagram.
For example, a student can be enrolled only in one course, but a
course can be enrolled by many students.
Student Course
(SID Name) ( CID C_name )
-------------- -----------------
1 A c1 Z
2 B c2 Y
3 C c3 X
4 D
Enroll
(SID CID)
----------
1 C1
2 C1
3 c3
4 C2
Now the question is, what should be the primary key for Enroll?
Should it be SID or CID or both combined into one. We can’t have CID
as the primary key because a CID can have multiple SIDs. (SID, CID) can
distinguish table uniquely, but it is not minimum. So SID is the primary
key for the relation enrollment.
For the above ER diagram, we considered three tables in the database
Student
Enroll
Course
But we can combine Student and Enroll table renamed as
Student_enroll.
Student_Enroll
( SID Name CID )
---------------------
1 A c1
2 B c1
3 C c3
4 D c2
Student and enroll tables are merged now.
So require a minimum of two DBMS tables for Student_enroll and
Course.
Note: In One to Many relationships we can have a minimum of two
tables.
Student Course
( SID Name) ( CID C_name )
-------------- -----------------
1 A c1 Z
2 B c2 Y
3 C c3 X
4 D
Enroll
( SID CID )
----------
1 C1
1 C2
2 C1
2 C2
3 c3
4 C2
Now, the same question arises. What is the primary key of Enroll
relation? If we carefully analyze, the primary key for Enroll table is (
SID, CID ).
But in this case, we can’t merge Enroll table with any one of the
Student and Course. If we try to merge Enroll with any one of the
Student and Course it will create redundant data.
Note: Minimum of three tables are required in the Many to Many
relationships.
ER Design Issues
The basic design issues of an ER database schema in the following
points:
Aggregation
Represents relationship between a whole object and its component.
Functional Dependency
The functional dependency is a relationshipthat exists between two
attributes. It typically exists between the primary key and non-key
attribute within a table.
X → Y
The left side of FD is known as a determinant, the right side of the
production is known as a dependent.
For example:
Emp_Id → Emp_Name
Example:
Example
ID → Name,
Name → DOB
Normalization
o Normalization is the process of organizing the data in the
database.
o Normalization divides the larger table into smaller and links them
using relationships.
Normal Description
Form
Advantages of Normalization
Disadvantages of Normalization
o You cannot start building the database before knowing what the
user needs.
o an atomic value.
o It states that an attribute of a table cannot hold multiple values. It
must hold only single-valued attributes.
1.First Normal Form:
14 John 7272826385, UP
9064738238
EMPLOYEE table:
The decomposition of the EMPLOYEE table into 1NF has been shown
below.
EMP_ID EMP_NAME EMP_PHONE EMP_STATE
14 John 7272826385 UP
14 John 9064738238 UP
Example: Let's assume, a school can store the data of teachers and the
subjects they teach. In a school, a teacher can teach more than one
subject.
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_ID TEACHER_AGE
25 30
47 35
83 38
TEACHER_DETAIL table:
TEACHER_SUBJECT table:
SUBJECT
25 Chemistry
25 Biology
47 English
83 Math
83 Computer
For a table to be in third normal form, it needs to satisfy the following
conditions:
Example:
EMPLOYEE_DETAIL table:
EMPLOYEE table:
201010 UP Noida
02228 US Boston
60007 US Chicago
06389 UK Norwich
462007 MP Bhopal
EMPLOYEE table:
EMP_ID → EMP_COUNTRY
Tech Cheap
The table is not in BCNF because neither EMP_DEPT nor EMP_ID alone
are keys.
EMP_COUNTRY table:
EMP_ID EMP_COUNTRY
264 India
264 India
EMP_DEPT table:
EMP_ID EMP_DEPT
D394 283
D394 300
D283 232
D283 549
Functional dependencies
1. EMP_ID → EMP_COUNTRY
2. EMP_DEPT → {DEPT_TYPE, EMP_DEPT_NO}
Candidate keys:
Forthefirsttable: EMP_ID
Forthesecondtable: EMP_DEPT
For the third table: {EMP_ID, EMP_DEPT}
Now, this is in BCNF because left side part of both the functional
dependencies is a key.
5.Fourth normal form (4NF)
o A relation will be in 4NF if it is in Boyce Codd normal form and has
no multi-valued dependency.
o For a dependency A → B, if for a single value of A, multiple values
of B exists, then the relation will be a multi-valued dependency.
ExampLE
STUDENT
21 Computer Dancing
21 Math Singing
34 Chemistry Dancing
74 Biology Cricket
59 Physics Hockey
The given STUDENT table is in 3NF, but the COURSE and HOBBY are two
independent entity. Hence, there is no relationship between COURSE
and HOBBY.
So to make the above table into 4NF, we can decompose it into two
tables:
STUDENT_COURSE
STU_ID COURSE
21 Computer
21 Math
34 Chemistry
74 Biology
59 Physics
STUDENT_HOBBY
STU_ID HOBBY
21 Dancing
21 Singing
34 Dancing
74 Cricket
59 Hockey
redundantly in the same table, and the person misses any of them,
then there will be multiple titles associated with the employee. The end
user has no way of knowing which is the correct title.
Conceptual Phase
The Conceptual phase lets you know the entities and the relation
between them. It describes the conceptual schema. The entities &
relations are defined here.
Logical Phase
Logical data model provides details about the data to the physical
phase. The physical process gives ER Diagram, data dictionary, schema,
etc that acts as a source for the physical design process.
Physical Phase
The physical database design allows the designer to decide on how the
database will be implemented.
---------XXX---------