Professional Documents
Culture Documents
03 - DBMS - Relational
03 - DBMS - Relational
Armstrong’s Axioms
Reflexivity: if X is subset of Y, then YX
Augmentation: if XY, then XZYZ for any Z
Transitivity: if XY and YZ, then XZ
Additional rules:
Union: if XY and XZ, then XYZ
Decomposition: if XYZ, then XY and XZ
Candidate Keys
1. Unique identification: Each non keys attribute is
functionally dependent on the key
2. Redundancy free: No attribute in the key can be
deleted without removing the property of unique
identification
Example: Employee (SSN, IDcard, Name,
Address, Born)
SSN → IDcard, Name, Address, Born
IDCard → SSN, Name, Address, Born
Name, Address, Born → SSN, IDcard
Keys
Key
Simple: consists one attribute
Composite key: consists more than one attribute
Primary key: The one of the candidates keys
are defined as primary key.
Foreign Key: An attribute in a relation that
serves as the primary key of another relation
in the same database
Benefit of the constraints
Automatically verified rules
Just definition is needed
The relational DBMS refuses a data
modification if it breaks a defined
constraints
Domain Constraints
All of the values in a column of a relation
must be taken from the same domain
Data type
Size (length)
Domain (allowable values, or range)
E.G.: passport number
String, 8 chars, first two chars are letter, the rest
are number
Entity Integrity
Every relation has primary key
Primary key or part of the primary key cannot
be null
Properties of the null value
Null value means undefined value
Not equal to 0
Not equal to an empty string
Not equal to anything else
A null vale is not equal to an another null value
Referential Integrity
Maintain consistency among the rows of two
relations
Each foreign key value must match a primary
key value in the other relation or else the
foreign key value must be null.
Example
Book (ISBN, Title, PublisherID)
Publisher(PublisherID, Name, Address)
Operational Constraints
Come from the business rules
Cannot be defined in relational data
model
Example:
Maximum 20 student can take an exam in
same time Limitation for number of
records
Relational Algebra
An algebra whose operands are relations or
variables that represent relations.
Operators are designed to do the most
common things that we need to do with
relations in a database.
The result is an algebra that can be used as a
query language for relations.
Relation Relation
Product Table
ID Description
I26 Screw
I35 Nail
I87 Hammer
I22 Digger
I98 Screw driver
I56 Scissors
I34 Brush
Cross Product
R3 = R1 x R2
Pair each record t1 of R1 with each record
t2 of R2.
Concatenation t1t2 is a record of R3.
Schema of R3 is the attributes of R1 and
R2, in order.
But beware attribute A of the same name
in R1 and R2: use R1.A and R2.A.
Product_Supplier table
ID Supplier
I26 S22
I87 S44
I22 S10
I28 S10
I98 S22
I98 S01
Theta-join
R3=(R1) C (R2)
(Product) (Product_Supplier)
Outer Join
Suppose we join R C S.
A record of R that has no record of S
with which it joins is said to be dangling
Outer join preserves dangling records
by padding them with a special NULL
symbol in the result.
Outer Join Example
(Product) (Product_Supplier)
FD:
Team_Name, Player_id → City, Player_name
Player_id → Player_name
Team_Name → City