Professional Documents
Culture Documents
Unit-2-ER-Relational-Mapping and Relational-Model
Unit-2-ER-Relational-Mapping and Relational-Model
Unit-2-ER-Relational-Mapping and Relational-Model
RV College of
Engineering
Dr. Shobha G
Professor, Department of CSE
RV College of Engineering, Bengaluru - 59 1
RV College of Go, change the world
Engineering
◼ For each regular (strong) entity type E in the ER schema, create a relation R
that includes all the simple attributes of E.
◼ Choose one of the key attributes of E as the primary key for R.
◼ If the chosen key of E is composite, the set of simple attributes that form it
will together form the primary key of R.
◼ SSN, DNUMBER, and PNUMBER are the primary keys for the relations
EMPLOYEE, DEPARTMENT, and PROJECT as shown.
4
FIGURE 7.1
The ER conceptual schema diagram for the COMPANY database.
Slide 7- 5
RV College of Go, change the world
Engineering
7
RV College of Go, change the world
Engineering
9
RV College of Go, change the world
Engineering
10
RV College of Go, change the world
Engineering
11
FIGURE 7.2
Result of mapping the COMPANY ER schema into a relational schema.
Slide 7- 12
RV College of Go, change the world
Engineering
13
RV College of Go, change the world
Engineering
14
RV College of Go, change the world
Engineering
15
RV College of Go, change the world
Engineering
16
RV College of Go, change the world
Engineering
18
RV College of Go, change the world
Engineering
INFORMAL DEFINITIONS
FORMAL DEFINITIONS
FORMAL DEFINITIONS
• A tuple is an ordered set of values
• Each value is derived from an appropriate domain.
A tuple is an ordered set of values
Each value is derived from an appropriate domain.
Each row in the CUSTOMER table may be called as a tuple
in the table and would consist of four values.
<632895, "John Smith", "101 Main St. Atlanta, GA 30332",
"(404) 894-2000"> is a triple belonging to the CUSTOMER
relation.
• Each row in the CUSTOMER table may be called as a tuple
• in the table and would consist of four values.
22
RV College of Go, change the world
Engineering
◼ The relation state is a subset of the Cartesian product of the domains of its
attributes
◼ Each domain contains the set of all possible values the attribute can take.
◼ The role these strings play in the CUSTOMER relation is that of the name of a
customer.
• Each value is derived from an appropriate domain.
Each row in the CUSTOMER table may be called as a tuple
• in the table and would consist of four values.
• <632895, "John Smith", "101 Main St. Atlanta, GA 30332",
• "(404) 894-2000"> is a triple belonging to the CUSTOMER
• relation.
25
RV College of Go, change the world
Engineering
26
RV College of Go, change the world
Engineering
The relation is formed over the cartesian product of the sets; each set has
values from a domain; that domain is used in a specific role which is
conveyed by the attribute name.
Formally,
Given R(A1, A2, .........., An)
r(R) subset-of dom (A1) X dom (A2) X ....X dom(An)
R: schema of the relation
r of R: a specific "value" or population of R.
R is also called the intension of a relation
r is also called the extension of a relation
Let S1 = {0,1}
Let S2 = {a,b,c}
Let R subset-of S1 X S2
for example: r(R) = {<0.a> , <0,b> , <1,c> } Manages : 1:1 relationship type between EMP LOYEE and DE
.
DEFINITION SUMMARY
1:1 relationship type between EMPLOYEE and DE
.
•ENT. Employee Informal Terms Formal Terms
• rved
29
RV College of Go, change the world
Engineering
2 Characteristics of Relations
Ordering of tuples in a relation r(R): The tuples are not
considered to be ordered, even though they appear to be
in the tabular form.
Ordering of attributes in a relation schema R (and of
values within each tuple):
We will consider the attributes in R(A1, A2, ..., An) and the
values in t=<v1, v2, ..., vn> to be ordered .
(However, a more general alternative definition of relation
does not require this ordering).
Values in a tuple: All values are considered atomic (indivisible). A special
null value is used to represent values that are unknown or inapplicable to
certain tuples.
Manages : 1:1 relationship type between EMPLOYEE and DE
ENT. Employee participation is partial. Department participation is not clear fro
• are the relationship types observed
30
RV College of Go, change the world
Engineering
31
RV College of Go, change the world
Engineering
32
RV College of Go, change the world
Engineering
• latioNotation:
Notation:
- We refer to component values of a tuple t by t[Ai] =
vi (the value of attribute Ai for tuple t).
Similarly, t[Au, Av, ..., Aw] refers to the subtuple of t
containing the values of attributes Au, Av, ..., Aw, respectively.
• - We refer to component values of a tuple t by t[A i] =
• vi (the value of attribute Ai for tuple t).
•
• Similarly, t[Au, Av , ..., Aw] refers to the subtuple of t
• containing the values of attributes A u, Av , ..., Aw, respectively.
Characteristics Of Relations
rtial. Department participation is not clear fro
(cont.)
◼ Values in a tuple:
◼ All values are considered atomic (indivisible).
◼ Each value in a tuple must be from the domain of the attribute for
that column
◼ If tuple t = <v1, v2, …, vn> is a tuple (row) in the relation state r of
R(A1, A2, …, An)
◼ Then each vi must be a value from dom(Ai)
Key Constraints
type between EMPLOYEE and DE
◼ Superkey (SK) of R:
◼ Is a set of attributes SK of R with the following condition:
◼ No two tuples in any valid relation state r(R) will have the same value for SK
◼ That is, for any distinct tuples t1 and t2 in r(R), t1[SK] t2[SK]
◼ This condition must hold in any valid state r(R)
◼ Key of R:
◼ A "minimal" superkey
◼ That is, a key is a superkey K such that removal of any attribute from K
results in a set of attributes that is not a superkey (does not possess the
superkey uniqueness property)
37
RV College of Go, change the world
Engineering
39
RV College of Go, change the world
Engineering
40
RV College of Go, change the world
Engineering
41
RV College of Go, change the world
Engineering
42
RV College of Go, change the world
Engineering
43
RV College of Go, change the world
Engineering
44
RV College of Go, change the world
Engineering
45
RV College of Go, change the world
Engineering
46
RV College of Go, change the world
Engineering
47
RV College of Go, change the world
Engineering
48
RV College of Go, change the world
Engineering
◼ Each relation will have many tuples in its current relation state
◼ The relational database state is a union of all the individual relation states
◼ Whenever the database is changed, a new state arises
◼ Basic operations for changing the database:
◼ INSERT a new tuple in a relation
◼ DELETE an existing tuple from a relation
◼ MODIFY an attribute of an existing tuple
◼ Next slide shows an example state for the COMPANY database
51
RV College of Go, change the world
Engineering
◼ UPDATE may violate domain constraint and NOT NULL constraint on an attribute being
modified
◼ Any of the other constraints may also be violated, depending on the attribute being
updated:
◼ Updating the primary key (PK):
◼ Similar to a DELETE followed by an INSERT
◼ Need to specify similar options to DELETE
◼ Updating a foreign key (FK):
◼ May violate referential integrity
◼ Updating an ordinary attribute (neither PK nor FK):
◼ Can only violate domain constraints
Thank YOU
59