DBMS Unit 2
DBMS Unit 2
Table Relation
Column Attribute/Domain
Row Tuple
Values in a column Domain
Table Definition Schema of a Relation
Populated Table Extension
Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition Chapter 5-10
Copyright © 2004 Ramez Elmasri and Shamkant Navathe
Example - Figure 5.1
● 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.
– For each weak entity type W in the ER schema with owner entity type
E, create a relation R and include all simple attributes (or simple
components of composite attributes) of W as attributes of R.
– In addition, include as foreign key attributes of R the primary key
attribute(s) of the relation(s) that correspond to the owner entity type(s).
– The primary key of R is the combination of the primary key(s) of the
owner(s) and the partial key of the weak entity type W, if any.
(2) Merged relation option: An alternate mapping of a 1:1 relationship type is possible by
merging the two entity types and the relationship into a single relation. This may be
appropriate when both participations are total.
(3) Cross-reference or relationship relation option: The third alternative is to set up a third
relation R for the purpose of cross-referencing the primary keys of the two relations S and
T representing the entity types.
– For each regular binary 1:N relationship type R, identify the relation S
that represent the participating entity type at the N-side of the
relationship type.
– Include as foreign key in S the primary key of the relation T that
represents the other entity type participating in R.
– Include any simple attributes of the 1:N relation type as attributes of S.
– For each regular binary M:N relationship type R, create a new relation S to
represent R.
– Include as foreign key attributes in S the primary keys of the relations that
represent the participating entity types; their combination will form the
primary key of S.
– Also include any simple attributes of the M:N relationship type (or simple
components of composite attributes) as attributes of S.
π
The general form of the project operation is <attribute list>(R) where π
(pi) is the symbol used to represent the project operation and <attribute list>
is the desired list of attributes from the attributes of relation R.
The project operation removes any duplicate tuples, so the result of the
project operation is a set of tuples and hence a valid relation.
– π (π <list2> (R) ) = π
<list1> <list1>
(R) as long as <list2> contains
the attributes in <list2>
− ρ S (B1, B2, …, Bn ) ( R) is a renamed relation S based on R with column names B1, B1,
…..Bn.
− ρ (B1, B2, …, Bn ) ( R) is a renamed relation with column names B1, B1, …..Bn which does
STUDENT∪INSTRUCTOR
Example: The result of the intersection operation (figure below) includes only
those who are both students and instructors.
STUDENT ∩ INSTRUCTOR
Example: The figure shows the names of students who are not instructors, and
the names of instructors who are not students.
STUDENT-INSTRUCTOR
INSTRUCTOR-STUDENT
● DIVISION Operation
– The division operation is applied to two relations
R(Z) ÷ S(X), where X subset Z. Let Y = Z - X (and hence Z
= X ∪ Y); that is, let Y be the set of attributes of R that are
not attributes of S.
– The result of DIVISION is a relation T(Y) that includes a
tuple t if tuples tR appear in R with tR [Y] = t, and with
tR [X] = ts for every tuple ts in S.
– For a tuple t to appear in the result T of the DIVISION, the
values in t must appear in R in combination with every tuple
in S.
Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition Chapter 6-67
Copyright © 2004 Ramez Elmasri and Shamkant Navathe
Binary Relational Operations (cont.)
DNO
ℱCOUNT SSN, AVERAGE Salary (Employee) groups employees by
DNO (department number) and computes the count of
employees and average salary per department.[ Note: count
just counts the number of rows, without removing duplicates]
DNOEMPLOYEE
EMPLOYEE)
RESULT ← π FNAME, LNAME, ADDRESS (RESEARCH_EMPS)