Professional Documents
Culture Documents
Chapter 4-2
Objectives
• To study the three main database design
phases
– Conceptual design
– Logical design
– Physical design
• Entities, Attributes, and Keys
• Relationships, Associations, and Constraints
• The ER Diagrams
• Mapping ER-models to relational tables
Database Development Life Cycle
Development of Database Systems involve the following steps:
1. Requirements Analysis
2. Design
A. Conceptual Database Design
B. Logical Database Design
C. Physical Design
3. Implementation - the testing and deployment of the
designed database
4. Operation and Support - administering and maintaining
the operation of the database system and providing
support to users
Database Design
4
24
Strong entity:
a regular entity type that have its own key
attribute
Weak entity :
an entity that cannot exist without the entity
with which it has a relationship
entity types that do not have key attributes of
their own
has a total participation constraint with respect
to its identifying relationship
Example
◼ Consider the entity type DEPENDENT, related to
EMPLOYEE
Strong vs Weak Entity Types
25
Default value
assumed value if no explicit value
Entity-Set and Keys
17
21
ONE-TO-ONE (1:1) one tuple is associated with only
one other tuple
E.g. Department-Employee: in manages
relationship since one
department have only one manager
ONE-TO-MANY (1:N) one tuple can be associated
with many other
tuples, but not the reverse
E.g. Department-Student: as one department can
have multiple students
Cardinality Ratio Types
MANY-TO-ONE (N:1) many tuples are associated with one
tuple but
• not the reverse
E.g. Employee – Department: as many employees belong
to a single
• department
MANY-TO-MANY (N:M) one tuple can be associated with
more
• than one other tuple and vice versa
E.g. Student – Course as a student can take many courses
and a single
• course can be attended by mCaonmypilsetdudBye-nStesble
N.
One-to-one relationship
Participation Constraint
specifies whether the existence of an entity
depends on its being related to another entity via
the relationship type
23
27
31
32
33
Relationship Cardinalities
Graphical Representations in ER Diagram
34
Participation Constraints
Summary of the notation for ER
diagrams
Summary of the notation for ER
diagrams
Summary of the notation for ER
diagrams
Example #1:Build an E-R Diagram for the following
information:
• A student record management system will have
the following two basic data object categories
with their own features or properties: Students
will have an Id, Name, Dept, Age, GPA and Course
will have an Id, Name, Credit Hours. Whenever a
student enroll in a course in a specific Academic
Year and Semester, the Student will have a grade
for the course.
Example #2:Build an ER Diagram for the following
information:
• A Personnel record management system will have
the following two basic data object categories
with their own features or properties: Employee
will have an Id, Name, DoB, Age, Tel and
Department will have an Id, Name, Location.
Whenever an Employee is assigned in one
Department, the duration of his stay in the
respective department should be registered.
ERDiagram Examples
35
logical data model/Design
• Map the conceptual model to a logical model
• Mapping entities and relationships in ER-
Diagram into tables
– Translate ER-diagram with constraints in to
relation
Cont’d
Step 2 Build and validate logical data model
– Step 2.1 Derive relations for logical data model
– Step 2.2 Validate relations using normalization
– Step 2.3 Validate relations against user
transactions
– Step 2.4 Define integrity constraints
Cont’d
• Step 2.5 Review logical data model with user
• Step 2.6 Merge logical data models into global
model (optional step)
• Step 2.7 Check for future growth
Relational Data Model
• Relational model represents the database as a collection
of relations, where each relation is a table with rows and
columns
• Relation: Two dimensional table
– Stores information or data in the form of tables : rows and
columns
• A row of the table is called tuple, equivalent to record
• A column of a table is called attribute, equivalent to fields
• Data value is the value of the Attribute
• In the relational model, each row in the table represents a
fact that typically corresponds to a real-world entity or
relationship
Cont’d
The building blocks of the relational data
model are:
– Entities: real world physical or logical object
– Attributes: properties used to describe each Entity
or real world object.
– Relationship: the association between Entities
– Constraints: rules that should be obeyed while
manipulating the data.
Types Of Relation
• Base Relation (Base Table)
– A Named Relation corresponding to an entity in the conceptual
schema, whose tuples are physically stored in the database
• View (Unnamed Relation)
– A View is the dynamic result of one or more relational
operations operating on the base relations to produce another
virtual relation that does not actually exist as presented
– produced upon request by a particular user at the time of
request
– can be created from single or different relations by extracting
some attributes and records with or without conditions
Purpose of View
• Hides unnecessary information from users: since only
part of the base relation (Some collection of attributes,
not necessarily all) are to be included in the view
• Provide powerful flexibility and security: since
unnecessary information will be hidden from the user
there will be some sort of data security.
• Provide customized view of the database for users:
each user is going to be interfaced with their own
preferred data set and format by making use of the
Views
Relation
• Definition: A relation is a named, two-dimensional table of
data
• Table is made up of rows (records), and columns (attribute
or field)
• Not all tables qualify as relations Requirements:
– Every relation has a unique name.
– Every attribute value is atomic (not multivalued not composite )
– Every row is unique (can’t have two rows with exactly the same
values for all their Fields )
– Attributes (columns) in tables have unique names
– Order of rows and columns is irrelevant
Correspondence with ER Model
⚫ Relations (tables) correspond with entity types
and with many-to-many relationship types
⚫ Rows correspond with entity instances and
with many- to-many relationship instances
⚫ Columns correspond with attributes
NOTE: The word relation (in relational
database) is NOT the same same the word
relationship (in ER model)
Key Fields
• Keys are special fields that serve two main purposes:
• Primary keys are unique identifiers of the relation in
question. Examples include employee numbers, social
security numbers, etc. This is how we can guarantee
that all rows are unique
• Foreign keys are identifiers that enable a dependent
relation (on the many side of a relationship) to refer to
its parent relation (on the one side of the relationship)
• Keys can be simple (a single field) or composite (more
than one field)
• Keys usually are used as indexes to speed up the
response to user queries
Figure 5-3 -- Schema for four relations
(Pine Valley Furniture)
Integrity Constraints
• Domain Constraints
– No value of the attribute should be beyond the
allowable limits
• Entity Integrity
– states that in a base relation, no attribute of a primary
key can assume a value of null. All primary key fields
MUST have data
• Enterprise Integrity Constraints:
– Additional rules specified by the users or database
administrators of a database are incorporated
Cont’d
• Referential Integrity – rule that states that any foreign
key value (on the relation of the many side) MUST
match a primary key value in the relation of the one
side. (Or the foreign key can be null)
For example: Delete Rules
– Restrict – don’t allow delete of“parent” side if related
rows exist in “dependent” side
– Cascade – automatically delete “dependent” side rows
that correspond with the “parent” side row to be deleted
– Set-to-Null – set the foreign key in the dependent side to
null if deleting from the parent side not allowed for
weak entities
Referential integrity constraints (Pine
Valley Furniture)
Transforming ER Diagrams in to
Relation
• Steps in mapping ER Conceptual Database Design
to Relational Model
1. Mapping of Strong Entity Types
2. Mapping of Weak Entity Types
3. Mapping of 1:1 Relationship Types
4. Mapping of 1:N Relationship Types
5. Mapping of M:N Relationship Type
6. Mapping of Multi-valued Attributes
7. Mapping of N-ary Relationship Types
Step 1 Mapping Regular Entities to Relations
• For each strong entity type E in the ER schema, create a
relation R that includes all the simple attributes of E.
• Simple attributes: E-R attributes map directly onto the
relation
• Composite attributes: Use only their simple, component
attributes
• Multi-valued Attribute - Becomes a separate relation with
a foreign key taken from the superior entity
• Choose one of the key attributes of E as primary key
for R
Mapping a regular entity