Chapter 2
Chapter 2
1
• To add new record type or relationship, the database must
be redefined and then stored in a new form.
Department
Employee
Job
Time Card
Activity
2. Network Model
• Allows record types to have more than one parent
unlike hierarchical model
• A network data models sees records as set members
• Each set has an owner and one or more members
• Allow many to many relationship between entities
• Like hierarchical model, network model is a collection of physically
linked records.
• Allow member records to have more than one owner
Department Job
2
Employee
Activity
Time Card
3
• No physical consideration of the storage is required by the user
• Many tables are merged together to come up with a new virtual
view of the relationship
Alternative terminologies
Relation Table File
Tuple Row Record
Attribut
e Column Field
4
• Is the collection of tables
o Each entity in one table
o Attributes are fields (columns) in table
• Order of rows and columns is immaterial
• Entries with repeating groups are said to be un-normalized
• Entries are single-valued
• Each column (field or attribute) has a distinct name
• All values in a column represent the same attribute and
have the same data format
5
• Whether the attribute is part of the entity identifier
(attributes which just describe an entity and those which
help to identify it uniquely)
• Whether it is permanent or time-varying (which
attributes may change their values over time)
• Whether it is required or optional for the entity (whose
values will sometimes be unknown or irrelevant)
Types of Attributes
(1) Simple (atomic) Vs Composite attributes
• Simple : contains a single value (not divided into sub
parts) E.g. Age, gender
• Composite: Divided into sub parts (composed of
other attributes)
E.g. Name, address
(2)Single-valued Vs multi-valued attributes
• Single-valued : have only single value(the
value may change but has only one value at one
time)
E.g. Name, Sex, Id. No. color_of_eyes
• Multi-Valued: have more than one
value E.g. Address, dependent-
name , Person may have several
college degrees
(3)Stored vs. Derived Attribute
• Stored : not possible to derive or
compute E.g. Name, Address
• Derived: The value may be derived (computed) from
the values of other attributes.
E.g. Age (current year – year of birth)
Length of employment (current date- start
date) Profit (earning-cost)
G.P.A (grade point/credit
hours) (4) Null Values
• NULL applies to attributes which are not
applicable or which do not have values.
• You may enter the value NA (meaning not applicable)
• Value of a key attribute can not be null.
Default value - assumed value if no explicit value
Entity versus Attributes
When designing the conceptual specification of the database, one
should pay attention to the distinction between an Entity and an
Attribute.
Consider designing a database of employees for an organization:
6
Should address be an attribute of Employees or an entity (connected to
Employees by a relationship)?
If we have several addresses per employee, address must be an
entity (attributes cannot be set-valued/multi valued)
If the structure (City, Woreda, Kebele, etc) is important, e.g. want
to retrieve employees in a given city, address must be
modeled as an entity (attribute values are atomic)
Degree of a Relationship
• An important point about a relationship is how many
entities participate in it. The number of entities
participating in a relationship is called the DEGREE of the
relationship.
• Among the Degrees of relationship, the following are the basic:
O UNARY/RECURSIVE RELATIONSHIP: Tuples/records of
a Single entity are related withy each other.
O BINARY RELATIONSHIPS: Tuples/records of two
entities are associated in a relationship
O TERNARY RELATIONSHIP: Tuples/records of three
different entities are associated
o And a generalized one:
N-NARY RELATIONSHIP: Tuples from
arbitrary numbers of entity sets are participating in
a relationship.
Cardinality of a Relationship
• Another important concept about relationship is the number of
instances/tuples that can be associated with a single instance from
7
one entity in a single relationship. The number of
instances participating or associated with a single instance from an
entity in a relationship is called the CARDINALITY of the
relationship. The major cardinalities of a relationship are:
o ONE-TO-ONE: one tuple is associated with only one other
tuple.
E.g. Building – Location as a single building will be
located in a single location and as a single location
will only accommodate a single Building.
o ONE-TO-MANY, one tuple can be associated with many other
tuples, but not the reverse.
E.g. Department-Student as one department can
have multiple students.
o MANY-TO-ONE, many tuples are associated with one tuple but
not the reverse.
E.g. Employee – Department: as many employees
belong to a single department.
o MANY-TO-MANY: one tuple is associated with many other
tuples and from the other side, with a different role name
one tuple will be associated with many tuples
E.g. Student – Courseas a student can take many
courses and a single course can be attended by many
students.
4. Relational Constraints/Integrity Rules
• Relational Integrity
¾ Domain Integrity: No value of the attribute should be
beyond the allowable limits
¾ Entity Integrity: In a base relation, no attribute of a
Primary Key can assume a value of NULL
¾ Referential Integrity: If a Foreign Key exists in a
relation, either the Foreign Key value must match a
Candidate Key value in its home relation or the Foreign
Key value must be NULL
¾ Enterprise Integrity: Additional rules specified by the
users or database administrators of a database are
incorporated
• Key constraints
If tuples are need to be unique in the database, and then we
need to make each tuple distinct. To do this we need to have
relational keys that uniquely identify each relation.
Super Key: an attribute or set of attributes that uniquely
identifies a tuple within a relation.
Candidate Key: a super key such that no proper subset of that
collection is a Super Key within the relation.
8
A candidate key has two properties:
1. Uniqueness
2. Irreducibility
If a super key is having only one attribute, it is
automatically a Candidate key.
If a candidate key consists of more than one
attribute it is called Composite Key.
Primary Key: the candidate key that is selected to identify tuples
uniquely within the relation.
The entire set of attributes in a relation can be
considered as a primary case in a worst case.
Foreign Key: an attribute, or set of attributes, within one
relation that matches the candidate key of some
relation.
A foreign key is a link between different relations to create
the view or the unnamed relation
Relational Views
Relations are perceived as a Table from the users’ perspective. Actually,
there are two kinds of relation in relational database. The two
categories or types of Relations are Named and Unnamed Relations.
The basic difference is on how the relation is created, used and
updated:
1. Base Relation
A Named Relation corresponding to an entity in the
conceptual schema, whose tuples are physically stored in the
database.
2. 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. So a view is
virtually derived relation that does not necessarily exist in the
database but can be produced upon request by a particular
user at the time of request. The virtual table or relation can be
created from single or different relations by extracting some
attributes and records with or without conditions.
Purpose of a 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 virtual table.
¾ 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 users are
going to be interfaced with their own preferred data set and
9
format by making use of the Views.
¾ A view of one base relation can be updated.
¾ Update on views derived from various relations is not
allowed since it may violate the integrity of the database.
¾ Update on view with aggregation and summary is not
allowed. Since aggregation and summary results are
computed from a base relation and does not exist actually.
10
¾ Valid state: the state that satisfies the structure and
constraints specified in the schema and is enforced by
DBMS
Since Instance is actual data of database at some point in time, changes
rapidly. To define a new database, we specify its database schema to
the DBMS (database is empty) .Database is initialized when we first
load it with data .
11