Beruflich Dokumente
Kultur Dokumente
Outline
• Degree of a relation
– Number of attributes
Relation
• Relation (or relation state)
– Set of n-tuples r = {t1, t2, ..., tm}
– Each n-tuple t
• Ordered list of n values t =<v1, v2, ..., vn>
• Each value vi is an element of dom(Ai) or is a special
NULL value
• Note:
– some relations represent entities, whereas others may represent
relationships.
Ordering in Relational Model
• Ordering of tuples in a relation
– Relation defined as a set of tuples
– No order
• Key of R
– minimal superkey of R
– Minimal:
• removal of any attribute from Key
– no longer a Superkey of R
CAR(Liscense_number, Engine_serial_number, Make, Model, Year)
• What are the following set of attributes? Superkey? Key?
• {License_number, Model}
• {Make, Model}
• {License_number, Engine_serial_number}
• {Engine_serial_number}
• {License_number}
Candidate keys: primary key, unique keys
When there are multiple keys (candidate keys), one is designated as the primary key
(underlined), other are called unique keys.
Entity Integrity Constraints
• If PK is the Primary Key, then
– t[PK] != NULL for any t
Referential Integrity Constraints
• Specified between two relations
• Maintains consistency among tuples in two
relations
Example
Referential Integrity Constraints
• Foreign key
– Relation schema R1 and R2
– A set of attributes FK in R1 is called a foreign
key of R1 that references R2, if
– The attributes in FK have the same domain(s)
as the primary key attributes in PK of R2
– Value of FK in a tuple t1 of the current state
either occurs as a value of PK for some tuple t2
in the current state or is NULL
Diagrammatically display referential integrity constraints: directed
arc from each foreign key to the relation it references
Basic Operations
• Basic operations that change the states of
relations in the database:
– Insert
– Delete
– Update (or Modify)
Insert Operations
• Insert a new tuple t
• Can violate any of the four types of constraints
• If an insertion violates one or more
constraints
– default option is to reject the insertion
Insert Operations Examples
a. Insert <‘Cecilia’, ‘F’, ‘Kolonsky’, NULL, ‘1960-04-05’, ‘6357
Windy Lane, Katy, TX’, ‘F’, 28000, NULL, 4> into EMPLOYEE
b. Insert
<‘Cecilia’, ‘F’, ‘Kolonsky’, ‘33344555’, ‘1960-04-05’,
‘6357 Windy Lane, Katy, TX’, ‘F’, 28000, NULL, 4> into
EMPLOYEE
c. Insert <‘Cecilia’, ‘F’, ‘Kolonsky’, ‘999457896’, ‘1960-04-05’,
‘6357 Windy Lane, Katy, TX’, ‘F’, 28000, NULL, 7> into
EMPLOYEE
Delete Operations
• Remove a tuple t
• Can violate only referential integrity
– Restrict: Reject the deletion
– Cascade: Propagate the deletion by deleting tuples that
reference the tuple that is being deleted
– Set null or set default: Modify the referencing attribute values
that cause the violation
Delete Operations Examples
a. Delete the EMPLOYEE tuple with Essn= ‘999887777’
Update Operations
• Change some attribute(s) of a tuple t
- Similar issues as with Insert/Delete
Update Operations Examples
– Update the Dno of the EMPLOYEE tuple with Ssn=
‘999887777’ to 7
– Update the Ssn of the EMPLOYEE tuple with Ssn=
‘999887777’ to ‘987654321’