Professional Documents
Culture Documents
Examples
Mapping (Table Design) Regular Entity
PROJECT
Name
ER Model
Relational Schema or ER Diagram
Number Name
ER Schema
Relational Schema
1 1
EMPLOYEE MANAGES DEPARTMENT
ER Model
Relational Schema
DEPARTMENT
Foreign Key
MGRSSN must be UNIQUE KEY to validate 1:1, Dname must has NOT NULL
constraint
… Mapping of 1:N Relationship Types
N 1
EMPLOYEE WORKS_FOR DEPARTMENT
ER Model
Relational Schema or ER Diagram
EMPLOYEE
DEPARTMENT
Loc2 Foreign Key
DNum DName Loc1
… -- Alternate Mapping of 1:N
Relationship Types
SSN … Sex Name Number Locations
N 1
EMPLOYEE WORKS_FOR DEPARTMENT
(1,N) (1,1)
ER Model
Relational Schema or ER Diagram
ESSN … Hours …
PNO
N M
EMPLOYEE WORKS_ON PROJECT
ER Model
Relational Schema or ER Diagram
WORKS_ON
ESSN
ER Model
Relational Schema or ER Diagram
Foreign Keys
Quantity must has NOT NULL constraint. Similar example can be Lecturer teaches course
to students. Other example: Vehicle, Policeman, Ticket (Ticket# is a serial unique number)
Representations in relational model
Relation is the base representation otherwise called as table.
Relation schema describes the structure of relation.
For Example: Student( student_id, student_name)
Relational Instance describes the table with sample data.
Relational Terms
Record or Tuple: Each row in the relation.
Domain: The set of allowable values for a column.
Degree: The number of columns in a relation.
Cardinality: The number of rows in a relation.
Relational database: a collection of relations with distinct
relation names.
Relational database schema: the collection of schemas for the
relations.
Instance of a relational database is a collection of relation
instances
Cardinality
1 N
PROFESSOR teaches CLASS
(1,1) (0,3)
M N
STUDENT enrolled CLASS
(0,35) (1,6)
A university may decide to limit a student to a max. of 6 classes per semester,
and class size may be limited to 35 students or no student.
(0,35) for class: class may contain no students or up to 35 students
(1,6) for student : student must take at least one class or up to 6 classes
-- Mapping of Weak Entity Types …
For each weak entity type W in the ER schema with owner entity
type E, create a relation R that includes all the simple attributes of
W (or simple components of composite attributes) as attributes of R.
29
… -- Mapping of Weak Entity Types
In the COMPANY database example, we created
the relation DEPENDENT, in this step to
correspond to the weak entity type DEPENDENT.
We include the primary key SSN of the
EMPLOYEE relation – which correspond to the
owner entity type as a foreign key attribute of
DEPENDENT; we renamed it ESSN; although
this is not necessary.
The primary key of dependent relation is the
combination {ESSN, DEPENDENT_NAME}
because DEPENDENT_NAME is the partial key
of the weak entity DEPENDENT.
30
--- Mapping Weak Entity DEPENDENT
SSN
… Sex Name Relationship BirthDate
1 M
EMPLOYEE Dependents_of DEPENDENT Gender
ER Schema
Relational Schema
DEPENDENT
31
- Mapping Relationship Types
32
-- Mapping of 1:1 Relationship Types …
33
… -- Mapping of 1:1 Relationship Types …
34
-- Mapping of 1:N Relationship Types …
35
… -- Mapping of 1:N Relationship Types …
36
-- Mapping of M:N Relationship Types …
37
… -- Mapping of M:N Relationship Types
38
-- Mapping of N-ary Relationship Types …
39
… -- Mapping of N-ary Relationship Types
40
- Mapping Multi-valued Attributes …
41
Integrity Constraints
They are rules that relation should satisfy for a relational instance.
Domain Constraints
Unique
Not Null
Key Constraints
Key Constraints
Primary Key Constraints
Rule that specifies a field to be a primary key.
A Primary Key is a field (Column) which is used to identify the whole
record.
Composite Key Constraints
Rule specifies one or more field as a primary key.
Foreign Key Constraints
Rule specifies a field to be a foreign key
Foreign key specifies a field which can be used to relate a table with
other table.