Lecture 2
Lecture 2
n Physical Data Independence – the ability to modify the physical schema without
changing the logical schema
l In general, the interfaces between the various levels and components should be
well defined so that changes in some parts do not seriously influence others.
l Database schema
l Integrity constraints
SQL
n SQL: widely used non-procedural language
Relational Model
n Relational model
n Entity Sets
n Relationship Sets
n Mapping Constraints
n Keys
n E-R Diagram
n Extended E-R Features
n Design of an E-R Database Schema
n Reduction of an E-R Schema to
Tables
Entity Sets
n A database can be modeled as:
l a collection of entities,
n An entity set is a set of entities of the same type that share the same properties.
Example: set of all persons, companies, trees, holidays
Attributes
n An entity is represented by a set of attributes, that is descriptive properties possessed
by all members of an entity set.
Example:
l Derived attributes
Can be computed from other attributes
E.g. age, given date of birth
Composite Attributes
Relationship Sets
n A relationship is an association among several entities
Example:
Hayes depositor A-102
customer entity relationship set account entity
n A relationship set is a mathematical relation among n 2 entities, each taken from
entity sets
{(e1, e2, … en) | e1 E1, e2 E2, …, en En}
l Example:
n For instance, the depositor relationship set between entity sets customer and account
may have the attribute access-date
Degree of a Relationship Set
n Refers to number of entity sets that participate in a relationship set.
n Relationship sets that involve two entity sets are binary (or degree two). Generally,
most relationship sets in a database system are binary.
n Relationships between more than two entity sets are rare. Most relationships are
binary. (More on this later.)
E-R Diagrams
Lines link attributes to entity sets and entity sets to relationship sets.
Entity Set
Many to many
Relationship Set
Many to one
Primary Key
Total Participation
Partial Key
E-R Diagram with Composite, Multivalued,
and Derived Attributes
Mapping Cardinalities
n Express the number of entities to which another entity can be associated via a
relationship set.
n For a binary relationship set the mapping cardinality must be one of the following types:
l One to one
l One to many
l Many to one
l Many to many
Mapping Cardinalities
One to one
One to many
Note: Some elements in A and B may not be mapped to any elements in the other set.
Mapping Cardinalities
Many to one Many to many
Note: Some elements in A and B may not be mapped to any elements in the other set.
One to one
Many to one
Many to Many
Relationship Sets with Attributes
Roles
n Entity sets of a relationship need not be distinct
n The labels “manager” and “worker” are called roles; they specify how employee entities
interact via the works-for relationship set.
n Roles are indicated in E-R diagrams by labeling the lines that connect diamonds to
rectangles.
n Role labels are optional, and are used to clarify semantics of the relationship
Cardinality Constraints
n We express cardinality constraints by drawing either a directed line (→), signifying
“one,” or an undirected line (—), signifying “many,” between the relationship set and
the entity set.
l A customer is associated with at most one loan via the relationship borrower
Many-To-Many Relationship
n A customer is associated with several (possibly 0) loans via borrower
If some courses are not enrolled by any of the student, the participation of course will be
partial.
Weak Entity Type and Identifying
Relationship
Then the relationship with course would be implicit in the course-number attribute