Professional Documents
Culture Documents
(0, 1) (1, 1)
PROJDEPT
single-valued vs. multi-valued
stored (or, base) vs. derived
key attributes: attributes whose values are distinct for
each individual entity instance (establishes a uniqueness
SUPERVISION
(0, N) constraint on entities)
a simple attribute is associated with a domain or value
set, specifying the valid values for the attribute
NOTE: DEPT
EMP.ename (lastname, firstname, middlename) -> composite composite multi-valued attributes may be nested (a.k.a.
{EMP.address} -> multi-valued: up to two addresses per
(deptid, dname)
complex attributes)
employee
EMP.age -> derived: current date - EMP.bday (in years)
1
relationship types/sets relationship types/sets
a relationship type, R, among entity types E1, E2,… En degree of a relationship type:
defines a set of association among entities from these number of entity types associated by the relationship
types (referred to as the participating entity types); may be one of unary (a.k.a. recursive relationships),
each relationship instance in R represents an association binary, ternary, … n-ary
which includes exactly one entity instance from each
participating entity type
a relationship type is characterized by its degree and its
structural constraints; furthermore, a relationship type
may also have attributes
one or more entity types may be associated via one or
more distinct relationship types
Structural Constraints
Structural Constraints
2
Example: Weak Entity Types
specialization/generalization specialization/generalization
specialization characteristics of specialization/generalization
typically used to denote that: subclass membership: entity instances of the
certain attributes (a.k.a. specific or specialized superclass that are members of a given subclass
are identified through defining attributes or
or local attributes) of the superclass may apply defining predicates
to some, but not all, of the superclass instances;
disjointness constraint: indicates whether the
the common (a.k.a. generalized) attributes are subclasses of the specialization are disjoint or
depicted on the superclass overlapping
some relationship types may be participated in completeness constraint: specifies whether or not
only by instances that are members of specific every instance in the superclass is a member of
subclasses some subclass in the specialization; may be total
or partial
in general, specialization/generalization may have
several levels
3
Example: Total Disjoint Specialization Example: Partial Overlapping Specialization
(empid, ename, etype, job) (payno, paydate, cashamt, chk,
ccard, gchk, totalamt)
EMPLOYEE
PAYMENT
etype
d
o
=“A” =“R”
chk = “Y” ccard = “Y”
(honorarium, trvlallowance) (hourlyrate, vaclv, scklv)
gchk = “Y”
ADMIN RANK&FILE
CHECK CCARD
(0, N)
(chkno, bank, chkdate, amt) (ccardno, cctype, ccinst,
(tcardno, month, yr, totalhrs) approvalno, amt)
TIMECARD GIFTCHECK
HAS
(1, 1)
(gchkno, expdate, amt)
4
relational data model: structure relational data model: structure
heading properties of a relation
attribute set of the relation there are no duplicate tuples: the combination of
the degree or arity of a relation represents the attribute values for each tuple must be unique
number of attributes tuples are unordered: the order in which the
body tuples occur is not important
set of tuples contained in the relation attributes are unordered: the order of attributes
the cardinality of a relation represents the number is not important as long as the correspondence
of tuples between attributes and their values is maintained
domain values are atomic: each value stored in
an attribute of any given tuple contains exactly
one logical value (normalized)
5
integrity of single relations integrity of single relations
entity integrity relational database scheme
keys may be simple or composite example 1
entity integrity rule CUSTOMERS(custid, custname, address)
for any relation, there can be no duplicate LOANS(loanno, loandate, loanamt, duedate,
tuples and that no candidate key values can
be null interest, custid)
entity integrity can be enforced by mechanisms PAYMENTS(orno, paydate, payamt, loanno)
provided by the dbms; operations (insert or
update) that create a duplicate candidate key or example 2
one containing nulls are rejected DEPT(deptno, dname, location)
constraints on null values AK dname
specifies whether or not null values are allowed EMP(empid, ename, job, deptno, sal, mgrid)
for the attributes in a relation
referential integrity
CUSTOMERS
referencing and referenced tuples
custid custname address
the referencing tuple contains the foreign key 184 Erap Estrada San Juan
value that represents a reference to the tuple
207 Cory Aquino Tarlac
containing the matching primary key value (the
referenced tuple) 285 Eddie Ramos Pangasinan
a referenced tuple may have many referencing 320 Ferdie Marcos Ilocos Norte
tuples associated with it
LOANS
not all tuples in the referenced relation are
loanno loandate loanamt duedate interest custid
referenced tuples
78-2007 Oct-08-2007 P 25,000.00 Oct-08-2008 P 2,500.00 184
foreign key attributes are not required to have the
same name as the primary key attributes being 79-2007 Dec-04-2007 P 10,000.00 Jun-03-2008 P 1,250.00 207
referenced; they should, however, be defined on 01-2008 Jan-10-2008 P 75,000.00 Apr-10-2008 P 7,500.00 184
the same domain
6
Example: Self-referencing Relation
Relational Database Scheme
DEPT(deptno, dname, location)
AK dname integrity among relations
EMP(empid, name, job, deptno, sal, mgrid)
FK deptno References DEPT Nulls Allowed
mgrid References EMP Nulls Allowed referential integrity
DEPT referential integrity rule
deptno dname location for all time, the relational database must not
10 Sales Cebu contain any unmatched foreign key value
20 Accounting Manila referential integrity may be violated when tuples
30 Purchasing Manila are inserted, deleted, or updated; can be enforced
by the dbms automatically or via application code
EMP
foreign key rules ensure that referential integrity is
empid name job deptno sal mgrid
imposed during delete and update operations
7200 George Bush Manager 10 P45,000.00 7560
Cascade
7405 Bill Clinton Programmer 20 P30,000.00 7720
Restrict
7560 Hilary Clinton President P95,000.00
7632 Al Gore Programmer 20 P25,000.00 7720
Nullify
7720 Fred Thompson Analyst 10 P75,000.00 7200
scenario
database systems Personnel in the Baguio Livelihood and Cooperative, Inc. (BLAC INC)
are organized into departments. A department must have at least two
employees belonging to it. Every department must have a head. Although
an employee works for a single department, he or she may be assigned to
be the head of at most three departments, regardless of what department
the employee belongs to. A corresponding honorarium, which may vary for
each department, is given to the head in addition to the basic salary. The
transformation from the assignment of department heads is done on rotation basis, hence, the dates
when such positions are assigned to an employee are monitored.
entity-relationship model to BLAC INC is a large complex composed of many buildings, and each
the relational data model department may have offices in any of these buildings. Specific rooms are
provided for the use of each department. A department may use many
rooms but cannot share rooms with other departments. To facilitate
communication, telephones are installed in every room.
Design a simple locator database that can keep information about the
company’s organizational and physical set-up.
7
E-R diagram: BLAC INC