Upload
phungtuong
View
217
Download
0
Embed Size (px)
Citation preview
1
I S 2 2 0 : D a t ab a s e F u n d a m e n t a l s
LECTURE 5:
THE RELATIONAL MODEL
Ref. “Chapter3” from
“Database Systems: A Practical Approach to Design, Implementation and Management.”
Thomas Connolly, Carolyn Begg.
Objectives2
Terminology of relational model.
How tables are used to represent data.
Properties of database relations.
How to identify CK, PK, and FKs.
Meaning of entity integrity and referential integrity.
Purpose and advantages of views.
Pearson Education © 2009
Logical Data Model
In this phase, the main objective is to translate the conceptual
data model created in phase 1 into a logical data model of
the data requirements of the enterprise.
The logical (relational) model represents the database as a
collection of relations. Informally, each relation resembles a
table of values or, to some extent, a file of records.
Lecture4
3
Relational Model Terminology4
A relation is a table with columns and rows.
Only applies to logical structure of the database, not the physical
structure.
Attribute is a named column of a relation.
Domain is the set of allowable values for one or more
attributes.
Relational Model Terminology5
Tuple is a row of a relation.
Degree is the number of attributes in a relation.
Cardinality is the number of tuples in a relation.
Relational Database is a collection of normalized relations
with distinct relation names.
Pearson Education © 2009
Database Relations9
Relation schema
Named relation defined by a set of attribute and
domain name pairs.
Relational database schema
Set of relation schemas, each with a distinct name.
Properties of Relations10
Relation name is distinct from all other relation names in relational schema.
Each cell of relation contains exactly one atomic (single) value.
Each attribute has a distinct name.
Values of an attribute are all from the same domain.
Each tuple is distinct; there are no duplicate tuples.
Order of attributes has no significance.
Order of tuples has no significance.
Relational Keys11
Candidate key (CK) An attribute, or set of attributes, that uniquely identifies a tuple, and no
proper subset is a CK within the relation.
Primary Key Candidate key selected to identify tuples uniquely within relation.
Alternate Keys Candidate keys that are not selected to be primary key.
Foreign Key Attribute, or set of attributes, within one relation that matches candidate key
of some (possibly same) relation.
Representing Relational Database Schemas
12
Branch (branchNo, street, city, postcode)
Staff (staffNo, fName, lName, position, sex, DOB, salary, branchNo)
Foreign Key1 branchNo references Branch(branchNo)
PropertyForRent (propertyNo, street, city, postcode, type, rooms, rent,
ownerNo, staffNo,branchNo)
Foreign Key1 staffNo references Staff(staffNo)
Foreign Key2 branchNo references Branch(branchNo)
Client (clientNo, fName, lName, telNo, prefType, maxRent)
Another way for specifying PK:
Branch (branchNo, street, city, postcode)
OR
Branch (branchNo, street, city, postcode)
Primary Key branchNo
13
Relational data Model comprising three components:
1. a structural part, consisting of a set of rules according to
which databases can be constructed. (which we discussed in
the previous sections and in the previous lecture: cardinality,
multiplicity and participation).
2. a manipulative part, defining the types of operation that
are allowed on the data (this includes the operations that are
used for updating or retrieving data from the database and
for changing the structure of the database);
3. a set of integrity constraints, which ensures that the data is
accurate.
Integrity Constraints14
Null
Represents value for an attribute that is currently unknown or
not applicable for tuple.
Deals with incomplete or exceptional data.
Represents the absence of a value and is not the same as zero
or spaces, which are values.
Integrity Constraints15
Entity Integrity
State that in a base relation, no attribute of a primary keycan be null.
Referential Integrity
If foreign key exists in a relation, either foreign key valuemust match a candidate key value of some tuple in its homerelation or foreign key value must be wholly null.
Integrity Constraints16
General Constraints
Additional rules specified by users or database
administrators that define or constrain some aspect of the
enterprise.
Pearson Education © 2009
Views17
Base Relation
A named relation corresponding to an entity in the conceptualschema, whose tuples are physically stored in database.
View
The dynamic result of one or more relational operationsoperating on base relations to produce another relation.
Pearson Education © 2009
Views18
A virtual relation that does not necessarily actually exist inthe database but is produced upon request, at time ofrequest.
Contents of a view are defined as a query on one or morebase relations.
Views are dynamic, meaning that changes made to baserelations that affect view attributes are immediately reflectedin the view.
Pearson Education © 2009
Purpose of Views19
Provides powerful and flexible security mechanism by hidingparts of database from certain users.
Permits users to access data in a customized way, so that samedata can be seen by different users in different ways, at sametime.
Can simplify complex operations on base relations.
Pearson Education © 2009