Presentation is loading. Please wait.

Presentation is loading. Please wait.

10/9/20151 The Relational Data Model TCU Database Systems Last update: September 2004 Reference: Elmasri 4 th edition, chapter 5.

Similar presentations


Presentation on theme: "10/9/20151 The Relational Data Model TCU Database Systems Last update: September 2004 Reference: Elmasri 4 th edition, chapter 5."— Presentation transcript:

1 10/9/20151 The Relational Data Model TCU Database Systems Last update: September 2004 Reference: Elmasri 4 th edition, chapter 5

2 10/9/20152 Introduction u Codd (1970) u Theoretical (mathematical) foundation u Concepts –relation data structure –integrity constraints u Operations –relational algebra and extensions

3 10/9/20153 Definitions u Figure 5.1 (informal definitions) u Domain D: a set of atomic (indivisible) values –{Names}, {valid GPA’s}, {valid grades} –must specify a data type {char(30)}, {[0.0,4.0]},{A,B,C,D,F} –dom(A i )=data type

4 10/9/20154 Definition: Relation Schema u think of as template or a Prolog predicate u R(A 1, A 2,...,A n ) where –R = relation name –A i =attribute –n = degree of relation R –example: PET(Name, Type, Breed, Birthdate, Weight)

5 10/9/20155 Definition: Relation u r(R): a relation r of the relation schema R(A 1,A 2,...,A n ) u set of n-tuples r={t 1, t 2,...,t m } –each n-tuple t is an ordered list, t=, where »v i is an element of dom(A i ) or null (unknown/D.N.E.) u More formally –a relation r(R) is a subset of the Cartesian product of the domains that define R u Max size (assuming finite domains):

6 10/9/20156 Definition: Relational DB Schema u Set of relation schemas AND integrity constraints u Figure 5.5 u A relational DB instance is a set of relation instances that satisfy the integrity constraints u Figure 5.6

7 10/9/20157 Characteristics of Relations u Row order (ordering of tuples) is insignificant –formally, but for performance it may be u Column order is insignificant –given a unique name or a fixed order u All values are atomic - can’t be subdivided –called the first normal form assumption –no composite attributes (e.g., address) –no multivalued attributes (e.g., car colors)

8 10/9/20158 Relational Model Constraints u Domain u Key u Entity Integrity u Referential Integrity u Others in section 5.2.5 and later in normalization u Generally no ability to declaratively specify –semantic integrity constraints (max hours all projects<56; salary<boss) –heuristics (folks usually weigh more than their age)

9 10/9/20159 Domain Constraint u attribute value is an atomic value from domain u Example domains (from Oracle) –number(l,d): l=length, d=decimal digits –char(size): fixed length –varchar(size): variable length char string –date –long: up to 2 GB –many allow subranges and enumerated data types

10 10/9/201510 Key Constraint u Each tuple in r is unique (a set) u superkey: any subset of attributes for which the values are unique in all valid DB states u key: a minimal superkey u candidate key: multiple keys may be possible u primary key: the candidate key selected –prefer integer key or key with fewest attributes u Figure 5.4

11 10/9/201511 Integrity Constraints u Entity Integrity –no primary key value can be null u Referential Integrity –foreign key »same domain as p.k. attribute of referenced schema »value equals an existing referenced attribute or is null (if not part of a p.k.) –Figures 5.6, 5.7

12 10/9/201512 u DBMS must enforce integrity constraints u Insert –can violate all 4 I.C.’s »DBMS rejects or asks for correction u Delete –can only violate referential integrity »reject/cascade/modify referencing attribute value (null, default or another tuple value) u Modify »can violate all 4 if p.k. or f.k. »else domain constraint only Updates examples pp 141-143


Download ppt "10/9/20151 The Relational Data Model TCU Database Systems Last update: September 2004 Reference: Elmasri 4 th edition, chapter 5."

Similar presentations


Ads by Google