Lecture Mid Term
Lecture Mid Term
Instructor:
Dr. Hamid Turab Mirza
agent
Stored in a standardized,
convenient form
Database Management
provide controlled System
A software system that is used to create, maintain, and
access to user databases
Order Filing
System
Relationships:
Relationship instance–link between entities (corresponds to
primary key-foreign key equivalencies in related tables)
Relationship type–category of relationship…link between
entity types
Entity
Attribute
symbols
symbols
A special entity
that is also a Relationship
relationship symbols
Relationship
degrees specify
number of
entity types Relationship
involved cardinalities
specify how
many of each
entity type is
allowed
What Should an Entity Be?
SHOULD BE:
An object that will have many
instances in the database
An object that will be composed of
multiple attributes
An object that we are trying to model
SHOULD NOT BE:
A user of the database system
An output of the database system
(e.g., a report)
Example of inappropriate entities
System System
user Inappropriate output
entities
Appropriate
entities
Attributes
Attribute–property or characteristic
of an entity or relationahip type
Classifications of attributes:
Required versus Optional Attributes
Simple versus Composite Attribute
Single-Valued versus Multivalued
Attribute
Stored versus Derived Attributes
Identifier Attributes
Identifiers (Keys)
Identifier (Key)–An attribute (or
combination of attributes) that
uniquely identifies individual
instances of an entity type
Simple versus Composite Identifier
Candidate Identifier–an attribute that
could be a key…satisfies the
requirements for being an identifier
Characteristics of Identifiers
Will not change in value
Will not be null
No intelligent identifiers (e.g.,
containing locations or people that
might change)
A composite attribute
An attribute
broken into
component parts
Multivalued
an employee can have
Derived
more than one skill
from date
employed
and current
date
Simple and composite identifier attributes
This attribute
that is both
multivalued
and
composite
Relationships
Examples of relationship types:
a) Relationship type
b)
Relationship
instances
Cardinality of Relationships
One-to-One
Each entity in the relationship will have exactly
one related entity
One-to-Many
An entity on one side of the relationship can
have many related entities, but an entity on
the other side will have a maximum of one
related entity
Many-to-Many
Entities on both sides of the relationship can
have many related entities on the other side
Cardinality Constraints
Cardinality Constraints - the number of
instances of one entity that can or must
be associated with each instance of
another entity
Minimum Cardinality
If zero, then optional
If one or more, then mandatory
Maximum Cardinality
The maximum number
Examples of cardinality constraints
a) Mandatory cardinalities
a) Optional cardinalities
A person is is
married to at
most one other
person, or may
not be married
at all
Sample E-R Diagram – 2
ABC housing society is a medium sized local authority. One of the responsibilities of the
Society is the maintenance and repair of Society owned housing within its boundaries. The
authority wishes to develop an information system to monitor information on housing
repair work, a description of which is as follows:
“For the purpose of housing repair work, the society is divided into a number of areas.
Each area is subdivided into streets or roads, each street or road in likely to have a number
of houses along it. Details of each house are held, along with details of each instance of
repair work carried out to a specific house. Each area is maintained by a single repair team,
although a team may be responsible for more than one area. A repair team consists of a
number of employees, one of whom is designated the team supervisor. The team are
allocated a number of vehicles for use in their work, which are generally used by the
“owning” team only, although are occasionally “borrowed” by other Teams. Each team is
based at a maintenance depot, and in some cases, more than one team may be based at a
single depot”.
Sample E-R Diagram - 2 (Entities
Identified)
ABC housing society is a medium sized local authority. One of the responsibilities of the
Society is the maintenance and repair of Society owned housing within its boundaries. The
authority wishes to develop an information system to monitor information on housing
repair work, a description of which is as follows:
“For the purpose of housing repair work, the society is divided into a number of areas.
Each area is subdivided into streets or roads, each street or road in likely to have a
number of houses along it. Details of each house are held, along with details of each
instance of repair work carried out to a specific house. Each area is maintained by a
single repair team, although a team may be responsible for more than one area. A repair
team consists of a number of employees, one of whom is designated the team supervisor.
The team are allocated a number of vehicles for use in their work, which are generally
used by the “owning” team only, although are occasionally “borrowed” by other Teams.
Each team is based at a maintenance depot, and in some cases, more than one team may be
based at a single depot”.
Relation
Definition: A relation is a named, two-dimensional
table of data
Table consists of rows (records) and columns
(attribute or field)
Requirements for a table to qualify as a
relation:
It must have a unique name
Every attribute value must be atomic (not multivalued, not
composite)
Every row must be unique (can’t have two rows with
exactly the same values for all their fields)
Attributes (columns) in tables must have unique names
The order of the columns must be irrelevant
The order of the rows must be irrelevant
Correspondence with E-R
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 as the word
relationship (in E-R 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 (Discussed Latter)
Schema for four relations (Pine Valley Furniture Company)
Primary Key
Foreign Key
(implements 1:N relationship
between customer and order)
Referential
integrity
constraints are
drawn via arrows
from dependent to
parent table
SQL table definitions
Referential
integrity
constraints are
implemented with
foreign key to
primary key
references
Transforming EER Diagrams
into Relations
Mapping Regular Entities to Relations
1. Simple attributes: E-R attributes map
directly onto the relation
2. Composite attributes: Use only their
simple, component attributes
3. Multivalued Attribute–Becomes a
separate relation with a foreign key
taken from the superior entity
Mapping a regular entity
(a) CUSTOMER
entity type with
simple
attributes
(a) CUSTOMER
entity type with
composite
attribute
(b) EMPLOYEE
relation with
recursive foreign
key
Mapping a unary M:N relationship
(a) Bill-of-materials
relationships (M:N)