Académique Documents
Professionnel Documents
Culture Documents
Chapter Objectives
The purpose of normailization Data redundancy and Update Anomalies Functional Dependencies The Process of Normalization First Normal Form (1NF) Second Normal Form (2NF) Third Normal Form (3NF)
What is Normalization?
Database designed based on the E-R model may have some amount of Inconsistency Uncertainty Redundancy To eliminate these draw backs some refinement has to be done on the database. This Refinement process is called Normalization Defined as a step-by-step process of decomposing a complex relation into a simple and stable data structure. The formal process that can be followed to achieve a good database design Also used to check that an existing design is of good quality The different stages of normalization are known as normal forms To accomplish normalization we need to understand the concept of Functional Dependencies.
Update Anomalies
Relations that have redundant data may have problems called update anomalies, which are classified as , Insertion anomalies Deletion anomalies Modification anomalies
To insert a new staff with branchNo B007 into the StaffBranch relation; To delete a tuple that represents the last member of staff located at a branch B007; To change the address of branch B003.
StaffBranch
staffNo
SL21 SG37 SG14 SA9 SG5 SL41
sName
John White Ann Beech David Ford Mary Howe Susan Brand Julie Lee
position
Manager Assistant Supervisor Assistant Manager Assistant
salary
30000 12000 18000 9000 24000 9000
branchNo bAddress
B005 B003 B003 B007 B003 B005 22 Deer Rd, London 163 Main St,Glasgow 163 Main St,Glasgow 16 Argyll St, Aberdeen 163 Main St,Glasgow 22 Deer Rd, London
sName
John White Ann Beech David Ford Mary Howe Susan Brand Julie Lee
position
Manager Assistant Supervisor Assistant Manager Assistant
salary
30000 12000 18000 9000 24000 9000
branceNo
B005 B003 B003 B007 B003 B005
Branch
branceNo
B005 B007 B003
bAddress
22 Deer Rd, London 16 Argyll St, Aberdeen 163 Main St,Glasgow
Functional Dependencies
Functional dependency describes the relationship between
attributes in a relation. For example, if A and B are attributes of relation R, and B is functionally dependent on A ( denoted A B), if each value of A is associated with exactly one value of B. ( A and B may each consist of one or more attributes.)
B is functionally
A
dependent on A
B
Refers to the attribute or group of attributes on the left-hand side of the arrow of a functional dependency
Determinant
Functional Dependencies (2) Trival functional dependency means that the right-hand side is a subset ( not necessarily a proper subset) of the lefthand side.
For example: (See Figure 1) staffNo, sName sName staffNo, sName staffNo They do not provide any additional information about possible integrity constraints on the values held by these attributes. We are normally more interested in nontrivial dependencies because they represent integrity constraints for the relation.
Functional Dependencies (3) Main characteristics of functional dependencies in normalization Have a one-to-one relationship between attribute(s) on the left- and right- hand side of a dependency; hold for all time; are nontrivial.
Inference Rules
A set of all functional dependencies that are implied by a given set of functional dependencies X is called closure of X, written X+. A set of inference rule is needed to compute X+ from X. Armstrongs axioms 1. 2. 3. 4. 5. 6. 7. If B is a subset of A, them A B Relfexivity: Augmentation: If A B, then A, C B Transitivity: If A B and B C, then A C Self-determination: A A Decomposition: If A B,C then A B and A C Union: If A B and A C, then A B,C Composition: If A B and C D, then A,C B,
Functional dependency
In a given relation R, X and Y are attributes. Attribute Y is functionally dependent on attribute X if each value of X determines EXACTLY ONE value of Y, which is represented as X -> Y (X can be composite in nature). We say here x determines y or y is functionally dependent on x XpY does not imply YpX If the value of an attribute Marks is known then the value of an attribute Grade is determined since MarkspGrade Types of functional dependencies:
Functional Dependencies
Consider the following Relation REPORT (STUDENT#,COURSE#, CourseName, IName, Room#, Marks, Grade) STUDENT# - Student Number COURSE# - Course Number CourseName - Course Name IName - Name of the Instructor who delivered the course Room# - Room number which is assigned to respective Instructor Marks - Scored in Course COURSE# by Student STUDENT# Grade - obtained by Student STUDENT# in Course COURSE#
COURSE# IName (Assuming one course is taught by one and only one Instructor) IName Room# (Assuming each Instructor has his/her own and non-shared room) Marks Grade
Dependency diagram
Report( S#,C#,SName,CTitle,LName,Room#,Marks,Grade)
S# SName C# CTitle, C# LName LName Room# C# Room# S# C# Marks Marks Grade S# C# Grade
S# SName Marks
Assumptions:
Each course has only one lecturer and each lecturer has a room. Grade is determined from Marks.
Full dependencies
X and Y are attributes. X Functionally determines Y Note: Subset of X should not functionally determine Y
Partial dependencies
X and Y are attributes. Attribute Y is partially dependent on the attribute X only if it is dependent on a sub-set of attribute X.
Transitive dependencies
X Y and Z are three attributes. X -> Y Y-> Z => X -> Z
C3 B3 P3 P3 B4 H6 M4
Bio Chemistry Botany Nuclear Physics Nuclear Physics Zoology American History Applied Mathematics
11 8
65 77 68 89 54 87 65
B B B A D A B
13 13 5 4
Basic Mathematics
pAddress
6 lawrence St,Glasgow 5 Novar Dr, Glasgow 6 lawrence St,Glasgow 2 Manor Rd, Glasgow 5 Novar Dr, Glasgow
rentStart
1-Jul-00
rentFinish
31-Aug-01
rent
350
ownerNo
CO40
oName
Tina Murphy Tony Shaw Tina Murphy Tony Shaw Tony Shaw
CR76
John kay
1-Sep-02 1-Sep-99
1-Sep-02 10-Jun-00
450 350
CO93 CO40
PG4
CR56
Aline Stewart
PG36
10-Oct-00
1-Dec-01
370
CO93
PG16
1-Nov-02
1-Aug-03
450
CO93
Definition of 1NF
First Normal Form is a relation in which the intersection of each row and column contains one and only one value. There are two approaches to removing repeating groups from unnormalized tables: 1. Removes the repeating groups by entering appropriate data in the empty columns of rows containing the repeating data. 2. Removes the repeating group by placing the repeating data, along with a copy of the original key attribute(s), in a separate relation. A primary key is identified for the new relation.
if and only if all the attributes of the relation R are atomic in nature. Atomic: the smallest level to which data may be broken down and remain meaningful
propertyNo
PG4 PG16 PG4
cName
John Kay John Kay Aline Stewart Aline Stewart Aline Stewart
pAddress
6 lawrence St,Glasgow 5 Novar Dr, Glasgow 6 lawrence St,Glasgow 2 Manor Rd, Glasgow 5 Novar Dr, Glasgow
rentStart
1-Jul-00 1-Sep-02 1-Sep-99
rentFinish
31-Aug-01 1-Sep-02 10-Jun-00
rent
350 450 350
ownerNo
CO40 CO93 CO40
oName
Tina Murphy Tony Shaw Tina Murphy Tony Shaw Tony Shaw
CR56
PG36
10-Oct-00
1-Dec-01
370
CO93
CR56
PG16
1-Nov-02
1-Aug-03
450
CO93
With the second approach, we remove the repeating group (property rented details) by placing the repeating data along with aClientNo of the original key attribute (clientNo) in a separte relation. copy cName
CR76 CR56 John Kay Aline Stewart
(clientNo, cName) (clientNo, propertyNo, pAddress, rentStart, rentFinish, rent, ownerNo, oName)
ClientNo
CR76 CR76 CR56 CR56 CR56
propertyNo
PG4 PG16 PG4 PG36 PG16
pAddress
6 lawrence St,Glasgow 5 Novar Dr, Glasgow 6 lawrence St,Glasgow 2 Manor Rd, Glasgow 5 Novar Dr, Glasgow
rentStart
1-Jul-00 1-Sep-02 1-Sep-99 10-Oct-00 1-Nov-02
rentFinish
31-Aug-01 1-Sep-02 10-Jun-00 1-Dec-01 1-Aug-03
rent
350 450 350 370 450
ownerNo
CO40 CO93 CO40 CO93 CO93
oName
Tina Murphy Tony Shaw Tina Murphy Tony Shaw Tony Shaw
Student_Course_Result Table
Student_Details
101 102 101 103 Davis Daniel Davis Sandra 11/4/1986 11/6/1987 11/4/1986 10/2/1988 M4 M4 H6 C3
Course_Details
Applied Mathematics Applied Mathematics American History Bio Chemistry Basic Chemistry Basic Mathematics Basic Mathematics 7 7 4 11
Results
11/11/2004 11/11/2004 11/22/2004 11/16/2004 82 62 79 65 A C B B
B3 P3 P3
8 13 13
77 68 89
B B A
B4 H6 M4
5 4 7
54 87 65
D A B
Table in 1NF
Rental
cName
John Kay Aline Stewart
ClientNo
CR76 CR76 CR56 CR56 CR56
propertyNo
PG4 PG16 PG4 PG36 PG16
rentStart
1-Jul-00 1-Sep-02 1-Sep-99 10-Oct-00 1-Nov-02
rentFinish
31-Aug-01 1-Sep-02 10-Jun-00 1-Dec-01 1-Aug-03
PropertyOwner
propertyNo
PG4 PG16 PG36
pAddress
6 lawrence St,Glasgow 5 Novar Dr, Glasgow 2 Manor Rd, Glasgow
rent
350 450 370
ownerNo
CO40 CO93 CO93
oName
Tina Murphy Tony Shaw Tony Shaw
Is a KEY Attribute
Is NON-KEY Attribute
Fully Functionally dependent on composite Primary key Partial Dependency with respect to the Primary Key
STUDENT TABLE
Student# StudentName DateofBirth M1 M4 H6 C1 C3 B3 P1 Basic Mathematics Applied Mathematics American History Basic Chemistry Bio Chemistry Botany Basic Physics Nuclear Physics Zoology
11
11-Nov-04
M1
7 4 5
11-Nov-04
C1
11 8 8
P3 07-Oct-1986 B4 06-Jun-1984
P1
13 5
12-Nov-04 27-Nov-04
101 M4 102 M4 101 H6 103 C3 104 B3 102 P3 105 P3 103 B4 105 H6 104 M4
DateofBirth
M1 Basic Mathematics Applied Mathematics American History Basic Chemistry Bio Chemistry Botany Basic Physics Nuclear Physics Zoology
Pre Requisit e
Duration InDays
11
M4 H6 C1 C3 B3 P1 P3 B4
M1
7 4 5
C1
11 8 8
P1
13 5
Course#
M4 M4 H6 C3 B3 P3 P3 B4 H6 M4
Marks
82 62 79 65 77 68 89 54 87 65
Grade
A C B B B B A D A B
DateOfExam
11-Nov-04
H6
22-Nov-04
C3
16-Nov-04
B3
26-Nov-04
P3
12-Nov-04
B4
27-Nov-04
Rental
fd1 fd5 fd6 clientNo, propertyNo rentStart, rentFinish clientNo, rentStart propertyNo, rentFinish propertyNo, rentStart clientNo, rentFinish (Primary Key) (Candidate key) (Candidate key)
PropertyOwner
fd3 fd4 propertyNo pAddress, rent, ownerNo, oName (Primary Key) ownerNo oName (Transitive Dependency)
Rental
cName
John Kay Aline Stewart
ClientNo
CR76 CR76 CR56 CR56 CR56
propertyNo
PG4 PG16 PG4 PG36 PG16
rentStart
1-Jul-00 1-Sep-02 1-Sep-99 10-Oct-00 1-Nov-02
rentFinish
31-Aug-01 1-Sep-02 10-Jun-00 1-Dec-01 1-Aug-03
PropertyOwner
propertyNo
PG4 PG16 PG36
Owner
rent
350 450 370
pAddress
6 lawrence St,Glasgow 5 Novar Dr, Glasgow 2 Manor Rd, Glasgow
ownerNo
CO40 CO93 CO93
ownerNo
CO40 CO93
oName
Tina Murphy Tony Shaw
Marks
3NF Tables
M4 M4 H6 C3 B3 P3 P3 B4 H6 82 62 79 65 77 68 89 54 87
Marks 82 62 79 65 77 68 89 54 87
Grade A C B B B B A D A
Third Normal Form Tables in 3 NF GRADE TABLE UpperB LowerB Grade ound ound 100 95 A+ 94 85 A 84 70 B 69 65 B64 55 C 54 45 D 44 0 E
Example of BCNF
fd1 fd2 fd3 fd4 clientNo, interviewDate interviewTime, staffNo, roomNo (Primary Key) staffNo, interviewDate, interviewTime clientNo (Candidate key) roomNo, interviewDate, interviewTime clientNo, staffNo (Candidate key) staffNo, interviewDate roomNo (not a candidate key)
As a consequece the ClientInterview relation may suffer from update anmalies. For example, two tuples have to be updated if the roomNo need be changed for staffNo SG5 on the 13-May-02.
ClientInterview
ClientNo
CR76 CR76 CR74 CR56
interviewDate
13-May-02 13-May-02 13-May-02 1-Jul-02
interviewTime
10.30 12.00 12.00 10.30
staffNo
SG5 SG5 SG37 SG5
roomNo
G101 G101 G102 G102
Example of BCNF(2)
To transform the ClientInterview relation to BCNF, we must remove the violating functional dependency by creating two new relations called Interview and SatffRoom as shown below, Interview (clientNo, interviewDate, interviewTime, staffNo) StaffRoom(staffNo, interviewDate, roomNo)
Interview
ClientNo
CR76 CR76 CR74 CR56
interviewDate
13-May-02 13-May-02 13-May-02 1-Jul-02
interviewTime
10.30 12.00 12.00 10.30
staffNo
SG5 SG5 SG37 SG5
StaffRoom
staffNo
SG5 SG37 SG5
interviewDate
13-May-02 13-May-02 1-Jul-02
roomNo
G101 G102 G102
Merits of Normalization
Normalization is based on a mathematical foundation. Removes the redundancy to a greater extent. After 3NF, data redundancy is
Demerits of Normalization
Data retrieval or SELECT operation performance will be severely affected. Normalization might not always represent real world scenarios.
Operation
Create separate rows or columns for every combination of multivalued columns Eliminate Partial dependencies Eliminate Transitive dependencies
Output
Table in 1 NF Tables in 2NF Tables in 3 NF
Keys
Candidate key Primary Key Alternate Key Super Key Foreign Key
Keys
Candidate key A Candidate key is a set of one or more attributes that can uniquely identify a row in a given table.
Keys
Candidate key
Keys
Primary key
During the creation of the table, the Database Designer chooses one of the Candidate Key from amongst the several available, to uniquely identify row in the given table.
Alternate Key
The candidate key that is chosen to perform the identification task is called the primary key and the remaining candidate keys are known as alternate keys. No of Alternate Keys = No of Candidate Keys - 1
Keys
Super key Any superset of a candidate Key is a super key. Example: Custid,CName can uniquely distinguish each tuple of the relation from the other ones. Thus it satisfies the property of uniqueness. Also Custid can alone distinguish each tuple of the relation from the others. Thus it too, satisfies the property of uniqueness. Therefore, Custid is the Candidate Key and Custid,CName(superset of candidate) is the super Key.
Keys
Foreign key
A Foreign Key is a set of attribute (s) whose values are required to match values of a Candidate key in the same or another table. EMP (Child /Referencing Table)
EmpNo 1001 1002 1003 1004 EName Elsa John Maria Maida EDeptNo D1 D2 Null D1
Point to remember Foreign key values do not (usually) have to be unique. Foreign keys can also be null .
Demos
Keys
Foreign key Points to remember A Foreign Key is a set of attributes of a table, whose values are required to match values of some Candidate Key in the same or another table The constraint that values of a given Foreign Key must match the values of the corresponding Candidate Key is known as Referential constraint A table which has a Foreign Key referring to its own Candidate Key is known as Self-Referencing table
Keys
Non-Key Attributes
The attributes other than the Candidate Key attributes in a table/relation are called Non-Key attributes. OR The attributes which do not participate in the Candidate key.
E R Modeling
Bottom Up approach
Normalization
ER modeling
ER modeling: A graphical technique for understanding and organizing the data independent of the actual database implementation. Entity: Any thing that may have an independent existence and about which we intend to collect data. Also known as Entity type. E.g.: Trainee Entity instance: a particular member of the entity type e.g. a particular trainee Attributes: Properties/characteristics that describe entities.eg: Trainee name, Batchname, DOB, Address, etc. Relationships: Associations between entities.E.g.: Trainee belongs to a Batch
Attributes
The set of possible values for an attribute is called the domain of the attribute Example: The domain of attribute marital status is having four values: single, married, divorced or widowed.
The domain of the attribute month is having twelve values ranging from January to December.
Key attribute: The attribute (or combination of attributes) that is unique for every entity instance E.g.: the account number of an account, the employee id of an employee etc. If the key consists of two or more attributes in combination, it is called a composite key
E.g. : years of service of employee can be calculated from date of joining and current date
Relationships
A relationship type between two entity types defines the set of all associations between these entity types Each instance of the relationship between members of these entity types is called a relationship instance E.g if Works-for is the relationship between the Employee entity and the department entity, then Rohan works-for IVS department, Riya works for ENR department ..etc are relationship instances of the relationship, worksfor
Degree of a Relationship
Degree: the number of entity types involved One Unary Two Binary Three Ternary E.g.: employee manager-of employee is unary employee works-for department is binary customer purchase item, shop keeper is a ternary relationship
Cardinality
Relationships can have different connectivity one-to-one (1:1) one-to-many (1:N) many-to- One (M:1) many-to-many (M:N) E.g.: Employee head-of department (1:1) Lecturer offers course (1:N) assuming a course is taught by a single lecturer Student enrolls course (M:N)
Person
Chair
One instance of entity type Person is related to one instance of the entity type Chair.
Demos
Organization
Employee
Demos
One instance of entity type Organization is related to multiple instances of entity type Employee
Cardinality Many-to-One
E1 E2 E3 E4 E5
Employee Department
Demos
D1 D2 D3
Cardinality Many-to-Many
S1 S2 S3 S4 C1 C2 C3 C4
Student
Course
Demos
Multiple instances of one Entity are related to multiple instances of another Entity.
Relationship Participation
Total : Every entity instance must be
connected through the relationship to another instance of the other participating entity types
ER Modeling - Notations
ER Modeling -Notations
An Entity is an object or concept about which business user wants to store information.
A weak Entity is dependent on another Entity to exist. Example Order Item depends upon Order Number for its existence. Without Order Number it is impossible to identify Order Item uniquely. Attributes are the properties or characteristics of an Entity A key attribute is the unique, distinguishing characteristic of the Entity A multi-valued attribute can have more than one value. For example, an employee Entity can have multiple skill values.
ER Modeling -Notations
A derived attribute is based on another attribute. For example, an employee's monthly salary is based on the employee's basic salary and House rent allowance. Relationships illustrate how two entities share information in the database structure.
To connect a weak Entity with others, you should use a weak relationship notation.
ER Modeling -Notations
Cardinality specifies how many instances of an Entity relate to one instance of another Entity. M,N both represent MANY and 1 represents ONE Cardinality
In some cases, entities can be selflinked. For example, employees can supervise other employees
Attributes
DOB Name Address
E#
Employee
Designatio n
Key attribute
DOB Name Address
E#
Employee
Designatio n
Multivalued Attribute
DOB Name Address Designatio n Employee
E#
skill set
Composite attribute
floor building
E#
Employee
Designatio n
Relationship
student
enrols in
course
Unary Relationship
Manages
Employee
Role names
Role names may be added to make the meaning more explicit
subordinate
Employee
Manager
Manages
Binary Relationship
Employee Works for Department
Ternary Relationship
Medicine
Doctor
Prescription
Patient
Relationship participation
Employee 1 head of 1
department
Attributes of a Relationship
Medicine
Doctor
Prescription
Patient
Weak entity
E# id
name
Employee
has
dependant
The dependant entity is represented by a double lined rectangle and the identifying relationship by a double lined diamond
Steps in ER Modeling
Identify the Entities Find relationships Identify the key attributes for every Entity Identify other relevant attributes Draw complete E-R diagram with all attributes including Primary Key Review your results with your Business users
Steps in ER Modeling
Steps in ER Modeling
Step 2: Find the relationships
One course is enrolled by multiple students and one student enrolls for multiple courses, hence the cardinality between course and student is Many to Many. The department offers many courses and each course belongs to only one department, hence the cardinality between department and course is One to Many. One department has multiple instructors and one instructor belongs to one and only one department , hence the cardinality between department and instructor is one to Many. Each department there is a Head of department and one instructor is Head of department ,hence the cardinality is one to one .
Steps in ER Modeling
Steps in ER Modeling
Step 5:
Draw complete E-R diagram with all attributes including Primary Key
Steps in ER Modeling
Identify the Entities Find relationships Identify the key attributes for every Entity Identify other relevant attributes Draw complete E-R diagram with all attributes including Primary Key Review your results with your Business users
Steps in ER Modeling
Step 1: Identify the Entities BANK BRANCH LOAN ACCOUNT CUSTOMER.
Steps in ER Modeling
Step 2: Find the relationships
One Bank has many branches and each branch belongs to only one bank, hence the cardinality between Bank and Branch is One to Many. One Branch offers many loans and each loan is associated with one branch, hence the cardinality between Branch and Loan is One to Many. One Branch maintains multiple accounts and each account is associated to one and only one Branch, hence the cardinality between Branch and Account is One to Many One Loan can be availed by multiple customers, and each Customer can avail multiple loans, hence the cardinality between Loan and Customer is Many to Many. One Customer can hold multiple accounts, and each Account can be held by multiple Customers, hence the cardinality between Customer and Account is Many to Many
Steps in ER Modeling
Step 3: Identify the key attributes BankCode (Bank Code) is the key attribute for the Entity Bank, as it identifies the bank uniquely Branch# (Branch Number) is the key attribute for Branch Entity Customer# (Customer Number) is the key attribute for Customer Entity Loan# (Loan Number) is the key attribute for Loan Entity Account No (Account Number) is the key attribute for Account Entity
Steps in ER Modeling
Step 4: Identify other relevant attributes For the Bank Entity, the relevant attributes other than BankCode would be Name and Address For the Branch Entity, the relevant attributes other than Branch# would be Name and Address For the Loan Entity, the relevant attribute other than Loan# would be Loan Type For the Account Entity, the relevant attribute other than Account No would be Account Type For the Customer Entity, the relevant attributes other than Customer# would be Name, Telephone# and Address
Steps in ER Modeling
Step 5: Draw complete E-R diagram with all attributes including Primary Key
Entity example
Here address is a composite attribute Years of service is a derived attribute (can be calculated from date of joining and current date)
Employee (E#, Name, Door_No, Street, City, Pincode, Date_Of_Joining)
And
Converting relationships
The way relationships are represented depends on the cardinality and the degree of the relationship The possible cardinalities are: 1:1, 1:M, N:M The degrees are: Unary Binary Ternary
Binary 1:1
Employee 1 head of 1 Department
Case 1: Combination of participation types The primary key of the partial participant will become the foreign key in the total participant. Employee( E#, EName,DateOfJoining,SkillSet) Department (Dept#, DName,Location,Head)
Demos
Binary 1 : 1
Department Dept# PK DName Location Head FK
Binary 1:1
Employee Sits_on CHAIR
The primary key of either of the participants can become a foreign key in the other Employee (EmpCode,EmpName,DateOfJoining) Chair( Item#, Model, Location, Used_by) (OR) Employee (EmpCode,EmpName,DateOfJoining,Sits_on) Chair (Item#, Model, Location)
Binary 1 : 1
Employee Table EmpCode PK EmpName DateofJoining Employee Table EmpCode PK EmpName DateofJoining Sits_On FK Chair Table Item# Model Location Used_By FK PK
OR
Chair Table Item# Model Location PK
Binary 1:N
Teacher 1 Teaches N Subject
The primary key of the relation on the 1 side of the relationship becomes a foreign key in the relation on the N side. Demos Teacher (TeacherID, Name, Telephone, Cabin) Subject (SubCode, SubName, Duration, TeacherID)
Binary 1 : N
Subject Teacher TeacherID Name Telephone Cabin PK SubCode SubName Duration TeacherID FK PK
Binary M:N
M Student Enrolls N Course
A new table is created to represent the relationship which contains two foreign keys - one from each of the participants in the relationship. The primary key of the new table is the combination of the two foreign keys. Student (StudentID,SName,DOB,Address) Course(CourseID,CName)
Demos
Binary M : N
Course CourseID Coursename PK
PK
PK / FK PK / FK
Unary 1:1
Consider employees who are also
a couple The primary key field itself will become foreign key in the same table
Demos
Unary 1 : 1
Employee Table E# EName DateofJoining SkillSet Spouse FK PK
Unary 1:N
The primary key field itself
will become foreign key in the same table. Same as unary 1:1
Unary 1 : N
Unary M:N
M Guarantor_of N Employee
There will be two resulting tables. One to represent the entity and another to represent the M:N relationship as follows Employee( E#, EName, DateOfJoining, SkillSet) Guaranty( Guarantor, Beneficiary)
Demos
Unary M : N
Guaranty Employee Table EmpCode EName DateofJoining SkillSet PK Beneficiary PK/FK Guarantor PK/FK
Ternary relationship
Represented by a new table. The new table contains three foreign keys - one from each of the participating Entities. The primary key of the new table is the combination of all three foreign keys. Prescription (DocID, PatCode, MedName)
Ternary
Prescription Doctor DocID Title PK DocID PatCode MedName NextVisit Patient PatCode PatName DOB Address PK Medicine MedName ExpDate PK PK / FK PK / FK PK/ FK
Weak Entity types are converted into a table of their own, with the primary key of the strong Entity acting as a foreign key in the table. This foreign key along with the partial key of the Weak Entity forms the composite primary key of this table. Example: s per this guideline, a Branch table can be created with the following structure. BRANCH (BankCode, Branch#, Name, Address)
Each relationship can be defined as separate table in relational schema. Key attributes of participating entities will become key attribute of the Relationship. Example: We can define Loan_Detail table with Loan# and Customer# together as primary key with other relevant attributes like DateOfSanction, InterestRate, LoanAmount, Duration etc. LOAN_DETAILS (Loan#, Customer#, DateofSanction, InterestRate, LoanAmount, Duration) Participating entities: The entities which are joined by the relation.
In a Many to Many relationship, it is necessary to create separate tables for the participating entities and the relationship. In the banking application we have Customer and Loan Entities have a Many to Many relationship. Hence one should create separate tables for CUSTOMER, LOANS and LOAN_DETAILS. Here LOAN_DETAILS refers to relationship table.
Summary
Most of the application errors are because of miscommunication between the application user and the designer and between the designer and the developer. It is always better to represent business findings in terms of picture to avoid miscommunication It is practically impossible to review the complete requirement document by business users. An E-R diagram is one of the many ways to represent business findings in pictorial format. E-R Modeling will also help the database design E-R modeling has some amount of inconsistency and anomalies associated with it.