A Brief History of Data Models  1950s file systems, punched cards

 1960s hierarchical Relational Data Model  IMS  1970s network  CODASYL, IDMS

 1980s relational  INGRES, ORACLE, DB2, Sybase  Paradox, dBase  1990s object oriented and object relational  O2, GemStone, Ontos

Relational Model COURSE

 Sets Courseno Subject Lecturer Machine  collections of items of the same type  no order domain range CS250 Programming Lindsey Sun  no duplicates 1:many CS260 Graphics Hubbold Sun  Mappings many:1 CS270 Micros Woods PC CS290 Verification Barringer Sun

1:1

many:many

Relational Model Notes Comparative Terms  no duplicate in a  a relation is a set of tuples Formal Oracle  no ordering of tuples in a relation Relation schema description  a relation is a set Relation Table  attributes of a relation have an implied Attribute ordering Domain Value set  but used as functions and referenced by name, not position  Notation  every tuple must have attribute values drawn Course (courseno, subject, from all of the domains of the relation or the equipment) special value NULL Student(studno,name,hons) Enrol(studno,courseno,labmark)  all a domain’s values and hence attribute’s values are atomic.

1 Keys

 SuperKey  a set of attributes in a relation that exactly  a set of attributes whose values together uniquely matches a (primary) key in another relation identify a tuple in a relation  the names of the attributes don’t have to be the  same but must be of the same domain  a superkey for which no proper subset is a  a foreign key in a relation A matching a primary superkey…a key that is minimal . key in a relation B represents a  Can be more than one for a relation  many:one relationship between A and B   a candidate key chosen to be the main key for the Student(studno,name,tutor,year) relation.  One for each relation Staff(lecturer,roomno,appraiser)  Keys can be composite

STUDENT studno name hons tutor year s1 jones ca bush 2 s2 brown cis kahn 2  Student(studno,name,tutor,year) s3 smith cs goble 2 s4 bloggs ca goble 1  Staff(lecturer,roomno,appraiser) s5 jones cs zobel 1 s6 peters ca kahn 3  CASCADE STAFF  delete all matching foreign key tuples lecturer roomno appraiser kahn IT206 watson eg. STUDENT bush 2.26 capon  RESTRICT goble 2.82 capon zobel 2.34 watson  can’t delete primary key tuple STAFF whilst a watson IT212 barringer foreign key tuple STUDENT matches woods IT204 barringer capon A14 watson  NULLIFY lindsey 2.10 woods  foreign key STUDENT.tutor set to if the barringer 2.125 null foreign key ids allowed to take on null

Entity Integrity and Nulls Relational Model

No part of a key can be null  General  Attribute values THREE categories of null  Simple  Atomic values 1. Not applicable  Flexible  Known domain 2. Not known  Easy to query declaratively without  Sometimes can be null 3. Absent (not recorded) programming STUDENT  But..... studno name hons tutor year thesis title  Good design essential s1 jones ca bush 2 null s2 brown cis kahn 2 null  Integrity essential s3 smith null goble 2 null s4 bloggs ca goble 1 null  Poor semantics s5 jones cs zobel 1 null  s6 peters ca kahn 3 null Relationships based on ‘value-matching’

2 Relational Design Informal guidelines

stud name tutor roomno course lab subject  Semantics of the attributes no no mark  easy to explain relation s1 jones bush 2.26 cs250 65 programming s1 jones bush 2.26 cs260 80 graphics  doesn’t mix concepts s1 jones bush 2.26 cs270 47 electronics s2 brown kahn IT206 cs250 67 programming  Reducing the redundant values in tuples s2 brown kahn IT206 cs270 65 electronics  s3 smith goble 2.82 cs270 49 electronics Choosing attribute domains that are atomic s4 bloggs goble 2.82 cs280 50 design  s5 jones zobel 2.34 cs250 0 programming Reducing the null values in tuples s6 peters kahn IT206 cs250 2 programming  null null capon A14 null null null Disallowing spurious tuples null null null null cs290 null specification s7 patel null null null null null

Definitions  (N)-tuple a set of (n) attribute-value pairs representing a single instance  Cartesian Product The cartesian product (×) between n sets is the set of a relation’s mapping between its domains. of all possible combinations of the elements of those sets.  Degree the number of attributes a relation has.  Domain set of all possible values for an attribute; for attribute A, the  Cardinality a number of tuples a relation has. domain is represented as dom(A). A domain has a format and a base data type.  Roles several attributes can have the same domain; the attributes indicate different roles in the relation.  Relation Schema denoted by R(A1, A2, …, An), is made up of relation name R and list of attributes A , A , …, A .  Key (SuperKey) a set of attributes whose values together uniquely 1 2 n identify every tuple in a relation. Let t1 and t2 be two tuples on relation  Relation a subset of the cartesian product of its domains. Given a r of relation schema R, and sk be a set of attributes whose values are the relation schema R, a relation on that schema r, a set of attributes A1..An key for the relation schema R, then t1[sk] ≠ t2[sk]. for that relation then  (Candidate) Key a (super)key that is minimal, i.e. has no proper ⊆ × × × r(R) (dom(A1) dom(A2) ... dom(An)) subsets that still uniquely identify every tuple in a relation. There can be several for one relation.  Attribute a function on a domain for each instance of the mapping or tuple  Primary Key a candidate key chosen to be the main key for the relation. There is only one for each relation.  Attribute Value the result of the attribute function. Each instance of the mapping is represented by one attribute value drawn from each  Foreign Key a candidate key of relation A situated in relation B. domain or a special NULL value. Given a tuple t and an attribute A for  Database a set of relations. a relation r, t[A]--> a, where a is the attribute’s value for that tuple.

3