Lecture 3
Lecture 3
MODEL
RELATIONAL MODEL
OBJECTIVES
To allow a high degree of data independence.
To provide substantial grounds for dealing with data
semantics, consistency, and redundancy problems.
TERMINOLOGY
Relation: A relation is a table with columns and rows.
A RDBMS requires only that the database be perceived by the
user as tables.
Attribute: An attribute is a named column of a relation.
A relation is represented as a two dimensional table in which the rows of the
table correspond to individual records and the table columns correspond to
attributes.
Domain:
EXAMPLE
DOMAIN
A domain is the set of allowable values for one or more
attributes.
Domains are an extremely powerful feature of the relational
model. Every attribute in a relation is defined on a domain
Tuple A tuple is a row of a relation.
The elements of a relation are the rows or tuples in the table.
In the Branch relation, each row contains four values, one for
each attribute.
Degree The degree of a relation is the number of attributes it
contains.
A relation with only one attribute would have degree one and
be called a unary relation or one-tuple. A relation with two
attributes is called binary, one with three attributes is called
ternary, and after that the term n-ary is usually used.
Cardinality The cardinality of a relation is the number of
tuples it contains.
EXERCISE
PROPERTIES OF
RELATIONS
the relation has a name that is distinct from all other relation
names in the relational schema;
each cell of the relation contains exactly one atomic (single)
value.
each attribute has a distinct name;
the values of an attribute are all from the same domain;
each tuple is distinct; there are no duplicate tuples;
the order of attributes has no significance;
the order of tuples has no significance, theoretically.
RELATIONAL KEYS
We need to be able to identify one or more attributes (called relational
keys) that uniquely identifies each tuple in a relation.
A DBMS key is an attribute or set of an attribute which helps you to identify
a row(tuple) in a relation(table).
WHY WE NEED KEYS?
Keys help you to identify any row of data in a table.
Allows you to establish a relationship between and identify the relation
between tables
Help you to enforce identity and integrity in the relationship
Super key An attribute, or set of attributes, that uniquely
identifies a tuple within a relation.
A superkey uniquely identifies each tuple within a relation.
However, a superkey may contain additional attributes that
are not necessary for unique identification
Candidate key A superkey such that no proper subset is a
superkey within the relation. CANDIDATE KEY is a set of
attributes that uniquely identify tuples in a table. Every table
must have at least a single candidate key. A table can have
multiple candidate keys but only a single primary key.
Uniqueness. In each tuple of R, the values of K uniquely identify that
tuple.
Irreducibility. No proper subset of K has the uniqueness property.
EXAMPLE
Student
sID sName Address City BOD Phone tutorID
1 Ali Tela Ali Amman 1/1/99 78987989 1
0
2 Sami Naowr Amman 3/2/00 98765432 1
1
3 Aya Khalda Amman 2/2/01 96543289 2
EXERCISE
Book (ISBN, title, edition, year) contains details of book titles in the library
and the ISBN is an id that identifies each book.
BookCopy (copyNo, available) contains details of the individual copies of
books in the library
Borrower (borrowerNo, borrowerName, address) contains details of library
members who can borrow .
BookLoan (dateout, dateDue) contains details of the book copies that are
borrowed by library members.
Task: Identify the relationships between tables and specify the primary keys
and the foreign keys in each table.
SOLUTION
EXAMPLE