3 Relational Data Modell
3 Relational Data Modell
Employees
EmpId Name BDate Sub City Kebele Phone
E001 Alemu Girma 01/10/70 Bole 06 011-663-0712
E004 Kelem Belete 12/04/68 Gulele 03 011-227-2525
Fig 2. Typical Employee relation instance
The columns in the table are representing the attributes of the relationship, and the rows (other
than the heading row) represent tuples (records) of the relation.
A relation in a relational model consists of:
The Relation schema: - that describes the column heads for the table and
The Relation instance: - that is the table with the set of tuples.
The set of relation schema forms schema for the relational database called database schema
(relational database schema).
In relational model the relation schema are described first. And the schema specifies
- The relation's name
- Name for each attribute (field or column)
- Domain of each attribute: - A domain is referred to in a relation schema by the domain
name and has a set of associated values.
Example
- Employees (EmpId:sting, Name:string, BDate:date, SubCity:string, Kebel:integer, Phone:string)
- Projects (PrjId:integer, Name:string, SDate:date, DDate:date, CDate:date)
- Teams (Name:string, Descr:string)
Properties of Relations
Rows (tuples) in a single relation are unique (that is; no two tuples are identical).
Relations are set of tuples not lists (that is; order of tuples in a relation is immaterial).
Attributes are atomic.
The values that appear in a column must be drawn from the domain associated with that
column.
The degree, also called arity, of a relation is the number of attributes in the relation.
3- 1/14
ECEG-4172 - Database System Relational Data Model
Key Constraints
A key constraint is a statement that a certain minimal subset of the attributes of a relation is a
unique identifier for a tuple in the relation.
A set of attributes that uniquely identifies a tuple according to a key constraint is called a candidate
key for the relation; often abbreviated just as key.
Key attributes in relational model are indicated by underlying the attributes in the relational.
Example
- Employees (EmpId, Name, BDate, SubCity, Kebel, Phone)
- Projects (PrjId, Name, SDate, DDate, CDate)
- Teams (Name, Descr)
REMARK: Note that a key for a relation may not be directly inferred from the high-level
conceptual models in some cases.
WorkSchedule Employees
… Hours Employee EmpId Name …
… 8 E001 E001 Alemu Girma …
… 6 E004 E004 Kelem Belete …
… 8 E002 E002 Mulken Getu …
… 4 E004
(a) Referencing relation (b) Referenced relation
Fig 2. Foreign Constraint in Relational Model
NOTE: - A single tuple can be referenced by zero or more tuples in the referencing relation, but a
single tuple with a single foreign key attribute can only reference one tuple.
- A foreign key could refer to the same relation.
- A relational database consists of related relations through a foreign key.
3- 2/14
ECEG-4172 - Database System Relational Data Model
Age
TEAMS Assigned EMPLOYEES
Address
Name
ProjId CustId Address
SDate DDate
Then the relations from the strong entity sets having only simple and single valued attributes
are as follows
- Projects(ProjId, Name, SDate, DDate)
- Customers(CustId, Name, Address)
Handling Weak Entity Sets
Suppose W is a weak entity set with attribute set {a1, a2, a3, … an} and identifying strong entity set
E. And let the primary key of E is the set {b1, b2, … bm}, then the attributes of the relation for the
weak entity set must include attributes for its complete key (including those belonging to the
identifying strong entity set) and its own, non-key attributes. That is, the set of attributes of the
mapping relation is {a1, a2, a3, … an} U {b1, b2, … bm}.
3- 3/14
ECEG-4172 - Database System attributes of weak entity set Relational Data Model
The primary key for the weak entity set relation thus include:
The discriminator of the weak entity set, and
The primary key of the identifying strong entity set.
Example
For the weak entity set (TEAMS) in figure 3 above the corresponding relation is:
- Teams(ProjId, Name, Descr)
Handling Composite and Multivalued Attributes
Composite attributes from E/R model to a relational model can be represented by creating
separate attributes for each of the components of the attributes (Note that the composite
attribute is not mapped directly into a separate attribute).
Multivalued attributes are handled by creating relations with the name of the attribute
having attributes that corresponds to the components of the multivalued attribute and the
primary key of the entity set or relationship set of which the attribute belongs. The primary
key for the newly created relation consists of:
- The primary key of the entity set or relationship set, and
- The attribute or set of attributes from the multivalued attribute.
Example
Consider the EMPLOYEES entity set in figure 3 above the corresponding relations for the
entity set are:
- Employees(EmpId, Name, BDate, Age)
- Addresses(City, SubCity, Kebele, HNo, Phone1, Phone2, EmpId)
REMARK
Note that; if the multivalued attribute has a fixed size of multiplicity (small size), it can be
represented by separate attributes for each multiplicity. For example consider phone attribute
above.
3- 4/14
ECEG-4172 - Database System Relational Data Model
NOTE: Supporting relationships (for example WorksOn) need not be transformed to relations if
their purpose is solely for identifying a weak entity set by passing on the identifying
strong entity set‟s primary key to the weak entity set; otherwise they will introduce
redundancy.
Suppose entity set E and F are related through a many-to-one relationship R from E to F, then it is
possible to join the relations for E and R that come out of this E/R model into a single relation S
with a schema consisting of:
All attributes of the entity set E,
The keys attributes of the entity set F, and
All Attributes of the relationship R.
If the participation of E into R is total it is also possible to include all attributes of F in the relation
S and have one single relation S in place of the three relations E, F and R.
The primary key for S would the primary key of E.
Example
Consider the entity sets “PROJECTS” and “CUSTOMERS” and the corresponding relationship
“Owns”, then we can have:
- Projects(ProjId, Name, SDate, DDate, CustId) and Customers(CustId, Name, Address), or
- Projects(ProjId, Name, SDate, DDate, CustId, Name, Address)
3- 5/14
ECEG-4172 - Database System Relational Data Model
Employees
EmpId Name BDate Sub City Kebele Phone
E001 Alemu Girma 01/10/70 Bole 06 011-663-0712
E001 Alemu Girma 01/10/70 Bole 06 011-663-0712
E004 Kelem Belete 12/04/68 Gulele 03 011-227-2525
3- 6/14
ECEG-4172 - Database System Relational Data Model
2. By separating out each set-valued attribute into a new relation and establishing a many-to-
many relationship.
3. By having multiple attributes sets for each set-valued attribute. This is applicable only if the
type constructor is fixed size array.
class Employee {
relationship Set <Team> assigned
inverse Team::formed;
};
class Team {
relationship Set <Employee> formed;
inverse Employee::assigned;
};
Then the corresponding relational models are
- Employees(EmpId, Name, Age, Gender, City, HAddr, Phone)
- Teams(TeamId, Name, Descr)
- Assigned(EmpId, TeamId)
For many-to-one or one-to-one relationship the relationship relation can be combined with the
many side relation as in the case of E/R realtionship.
Example:
- Consider the one-to-many relationship between “PROJECTS” and “CUSTOMERS”
class Project {
relationship <Customer> ownedBy
inverse Customers::owns;
};
class Customer {
relationship Set <Project> owns;
inverse Projects::ownedBy;
};
Then the corresponding relational models are
- Projects(ProjId, Name, SDate, DDate, CustId)
- Customers(CustId, Name, Address)
3- 7/14
ECEG-4172 - Database System Relational Data Model
Dependencies
In a database design the two most common pitfalls that result in bad designing are:
Repetition of information, and
Inability to present certain information (Loss of information).
Functional Dependencies
Functional dependency is a kind of constraint that helps to remove redundancy in relational
database design.
Defintion: Functional dependency denoted by X A is an assertion about a relation R that
whenever two tuples of R agree on all the attributes of X, then they must also agree on
the attribute A. We say that “X A holds in R” or “X functional determines A”
Note that in the notation X A; X represent sets of attributes and A represent single
attribute. That is A1 A2 A3…An B
The functional dependency is a generalization of the notion of superkey.
Example:
- Consider the Teams relation: Teams(PrjId, Name, Descr), then
PrjId, Name Descr
- For the Employees relation:
Employees(EmpId, NationalId, Name, BDate, Age, Gender, City, HAddr, Phone)
EmpId Name; EmpId Age; Name BDate Gender
A functional dependency A1 A2 A3…An B is said to be trivial dependency if B is an element or of
{A1, A2, A3…An}.
3- 8/14
ECEG-4172 - Database System Relational Data Model
attributes B that are functionally determined from the set S. That is; A1 A2 …An B follows
from the set S. The closure set of attributes A1, A2, …An is denoted by {A1, A2, …An}+
The closure set of attributes can be determined by repeatedly applying the following three rules
known as Armstrong’s Axioms:
Reflexivity Rule
If α is set of attributes and β C α then, α β holds.
Augmentation Rule
If α β holds and γ is set of attributes, then γα γβ holds.
Transitivity Rule
If α β holds and β γ holds, then α γ holds.
Algorithm for computing the closure of X, X+ is given below.
1. Let X be a set of attributes that eventually will become the closure. First, we initialize X to
be X.
2. Now, we repeatedly search for some functional dependency B1 B2 …Bm C Such that all of
B1, B2...Bm are in the set of attributes X but C is not. We then add C to the set X.
3. Repeat step 2 as many times as necessary until no more attributes can be added to X.
4. The set X, after no more attributes can be added to it, is the closure set X+.
Example: Consider a relation with attributes A, B, C, D, E, and F. Suppose that this relation has
the functional dependencies AB C, BC AD, D E, and CF B. What is the
closure of {A, B}, that is {A, B}?
Solution:
X = {A, B}
From the function dependency AB C, we add C to X that is X = {A, B, C}
Similarly; BC AD X = {A, B, C, D}
D E X = {A, B, C, D, E}
No more changes in X are possible. Thus {A, B}+ = {A, B, C, D, E}
From the closure set it is to follow that AB D
Exercise: Test whether D A flows from the functional dependency set?
To test for D A, first determine the closure set of {D}
X = {D}
From the function dependency D E, we add E to X that is X = {D, E}
No more changes in X are possible. Thus {D}+ = {D, E}
From the closure set D A does not hold.
Multivalued Dependencies
Multivalued dependency for a relation R, is defined as a constraint when the values of one set of
attributes is fixed, then the values in certain other attributes are independent of values of all the
other attributes in R.
3- 9/14
ECEG-4172 - Database System Relational Data Model
That is; for a multivalued dependency X Y in R where X and Y are subsets of the set of
attributes in R, if t and u are tuples in the relational instance r for the schema R, then there exist a
third tuple v that agrees:
1. with both t and u on X‟s,
2. with t on Y‟s, and
3. with u on all attributes of R that are not among X‟s or Y‟s (R – (X U Y)).
3- 10/14
ECEG-4172 - Database System Relational Data Model
3- 11/14
ECEG-4172 - Database System Relational Data Model
While denormalization can boost storage and query performance, it can also have negative effects.
For example, by adding redundant data to tables, you risk the following problems:
More data means the RDBMS has to read more data pages than otherwise needed,
hurting performance.
Redundant data can lead to data anomalies and bad data.
In many cases, extra code will have to be written to keep redundant data in separate
tables in synch, which adds to database overhead.
Normal Forms
Normalization procedure provides:
A framework for analyzing relation schemas based on functional and multivalued
dependencies.
A series of normal form test that can be carried out on individual relation schemas so
that the relational database can be normalized to any degree.
Normalization through decomposition need to preserve the existence of two additional properties of
a relational schema:
Lossless or Nonadditive Join: Nonadditive join property guarantees that the spurious
tuple generation does not occur after decomposition
Dependency Preservation: Dependency preservation ensures that each functional
dependency is presented in one of the individual relation resulting after decomposition.
3- 12/14
ECEG-4172 - Database System Relational Data Model
3- 13/14
ECEG-4172 - Database System Relational Data Model
3- 14/14