Sie sind auf Seite 1von 26

Basic Relational Model

Outline

•  Relational Data Model Concepts


•  Relational Model Constraints
•  Update Operations and Dealing with
Constraint Violation
Relational Model Concepts
•  Concept: Relation
–  Represents data as a collection of relations
–  Table of values
Relation Schema
•  Relation schema R
–  Denoted by R(A1, A2, ...,An)
–  R: relation name
–  A1, A2, ..., An: attribute names

•  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

•  Ordering of values within a tuple


–  Attributes and the values within tuples are ordered
Values in Tuples
•  Flat relational model
•  Each value in a tuple is atomic
•  Not divisible
•  Composite and multivalued attributes not allowed
•  Composite attributes
•  Represented only by simple component attributes.
•  Multivalued attributes
•  Must be represented by separate relations
NULLs in Tuples
•  NULL values
–  Value unknown
–  Value exists but is not available
–  Attribute does not apply to this tuple (value
undefined)
Notations
•  Relation schema R of degree n
–  R(A1, A2, ..., An)
–  R.A1: Attribute A1 of R
•  n-tuple t in a relation schema R
–  Denoted by t = <v1, v2, ..., vn>
–  vi is the value corresponding to attribute Ai
–  t[Ai] or t. Ai refers to the value vi in t for attribute Ai
–  t[Au, Aw, ..., Az] or t.(Au, Aw, ..., Az) refers to the
subtuple of values <vu, vw, ..., vz> from t
corresponding to the attributes specified in the list
Relational Model Constraints
•  Restrictions on the actual values in a relational
schema
•  Derived from the rules in the “miniworld” that the
database represents

•  Four types of constraints


1.  Domain Constraints
2.  Key Constraints
3.  Entity integrity constraints
4.  Referential integrity constraints
Domain Constraints
•  t[Ai] ∈ dom( Ai), for all t, Ai
–  Numeric data types for integers and real numbers
–  Characters
–  Booleans
–  Fixed-length strings
–  Variable-length strings
–  Date, time, timestamp
–  Fixed format
Key Constraints
•  No two tuples are the same.
–  Have the same values for all attributes
•  Superkey of R
–  A set of attributes, SK, of R such that

t1[ SK] != t2[SK] whenever t1 ≠ t2 in any state

•  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’

Reading Assignment: Chapter 3  

Das könnte Ihnen auch gefallen