Dbday1
Dbday1
Mohamed ELshafei
ER Model
Entity Relationship Diagram
Concepts
Importance of ER Model
access-date
cust-name number
cust-id
cust-city balance
Candidate Key
Primary Key
Foreign Key
Composite Key
Partial Key
Alternate key
Super Key
Primary Key
Candidate Key :
when multiple possible identifiers exist, each is a candidate key.
Foreign Keys :
Foreign keys reference a related table through the primary key of that
related table.
Referential Integrity Constraint:
For every value of a foreign key there is a primary key with that value in
the referenced table e.g. if student name is to be used in a dormitory
table then that name must exist in the student table.
Attribute
Means the attribute value is atomic and can’t be further divided, such
as a phone number.
access-date
cust-name number
cust-id
cust-city balance
Composite Attribute
Name
year
month
Derived Attribute
date-of-birth
Emp
Salary
Deduction
Net Salary
Multi-valued
customer
phone no.
Complex Attribute
multi-valued + Composite
address
customer
Relationship
Degree of Relationships
Cardinality Constraint
Participation Constraint
Degree of Relationships
One-One Relationship
One-Many Relationship
Many- Many Relationship
Mapping Cardinalities
1 1
One-to-One Employee own Car
M
1
One-to-Many Department has Employee
M M
Many-to-Many Course take Student
PARTICIPATION CONSTRAINT
A data structure through which data is stored in tables that are related
to one another in some way.
The way the tables are related is described through a relationship.
Intake 39 - DB
Basic Database Structure
Intake 39 - DB
Mapping
ERD Mapping to Tables
Steps
Intake 39 - DB
ER-to-Relational Mapping
Intake 39 - DB
Mapping Composite attribute
Intake 39 - DB
Mapping Multivalued Attribute
Intake 39 - DB
Mapping Derived & Complex
Intake 39 - DB
Step 2: Mapping of Weak Entity Types
Intake 39 - DB
One To One 2 Mandatory
1 table
Emp(EID, Ename, Cname, CID)
tbl_xy (PK,….,…,….)
PK = PKx or PKy
Intake 39 - DB
One To One Optional-Mandatory
Employee(EID, Ename)
2 tables
tbl_x (PKx,….,…….) Computer(CID, Cname, EID_FK)
tbl_y (PKy,….,….,PKx….)
Intake 39 - DB
One To One 2 Optional
3 tables
Employee(EID, Ename)
tbl_x (PKx,….,…….)
tbl_y (PKy,….,…….) Car(CID, CType)
tbl_xy (PKxy,….,…,FKxy,….)
Emp_Car(EID, CID_FK) Intake 39 - DB
PKxy = PKx or PKy
Step 4: Mapping of Binary 1:N Relationship Types
Intake 39 - DB
One To Many (Many is Mandatory)
3 tables
Project(PID, Pname)
tbl_x (PKx,….,…….)
tbl_y (PKy,….,…….) Employee(EID, Ename)
tbl_xy (PKxy,….,…….)
PKxy = PKy Proj_Emp(EID,PID_FK) Intake 39 - DB
Step 5: Mapping of Binary M:N Relationship
Types.
Intake 39 - DB
Many To Many
CNam
SID SName CID
e
Many-to-Many
M M
Student take Course
X whatever– Y whatever
3 tables
Student(SID, Sname)
tbl_x (PKx,….,…….)
tbl_y (PKy,….,…….) Course(CID, Cname)
tbl_xy (PKx ,PKy, ….,…….)
PKxy= PKx+PKy Stud_Course(SID, CID) Intake 39 - DB
Many To Many with attribute
Intake 39 - DB
Step 6: Mapping of N-ary Relationship
Types.
If n > 2 then :
Create a new third table.
Add FKs to the new table for all parent tables.
Add simple attributes of relationship to the new table if any .
Intake 39 - DB
Step 6: Mapping of N-ary Relationship
Types.
Intake 39 - DB
Step 7:Mapping Unary Relationship
Intake 39 - DB
Case Study
Company
Intake 39 - DB
Case study
Intake 39 - DB
Result
Intake 39 - DB
Intake 39 - DB
Result
Student(St-id,st-fname,st-Lname,st-age,st-super,Dept-ID)
Course(Crs-id.Crs-Name,Crs-Duration,Top-id)
Topic(Top-ID,Top-Name)
Stud-Course(St-ID,Crs-ID,grade)
Instructor(Ins-ID,ins-Name,Address,Salary,Dept-ID)
Ins-Course(Ins-ID,Crs-ID,Evalution)
Department(Dept-ID,Dept-Name,Manager-ID,HireDate)
Intake 39 - DB