90 likes | 234 Views
Relational Model. Database Management Systems, 3 rd ed., Ramakrishnan and Gehrke, Chapter 3. Relation.
E N D
Relational Model Database Management Systems, 3rd ed., Ramakrishnan and Gehrke, Chapter 3
Relation Given a collection of (not necessarily distinct) sets D1, D2, …, Dn, r(R) is a relation on those n sets if it is a set of ordered n-tuples <d1, d2, …, dn> such that d1 D1, d2 D2, …, and dn Dn. Sets D1, D2, …, Dn are the domains of r(R). n is the degree or arity of r(R). Formal defns. taken from Fundamentals of Database Systems by Elmasri and Navathe
Relation Schema A relation schema or intension R, denoted by R (A1, A2, …, A), is a set of attributes R = {A1, A2, …, An}. Example of relation schema: Student (ID: string, Name: string, Age: integer, Gender: char) Relation r of the relation schema R, denoted r(R), is an instance or extension of the schema. E.g.: <2739, Peter Wong, 20, M>
Relationship to Predicate Logic Codd based relational model, in part, on predicate logic. Think of relation schema as a predicate. Example: Father (NameOfSon, NameOfFather) <John Doe, Joe Doe> <Joe Doe, Bob Doe> Rule: If x is the father of y, and y is the father of z, then x is the grandfather of z.
Relationship to Set Theory • No duplicate tuples (although allowed by most commercial DBMSs) • Significance of ordering of attributes in tuples (although generally ignored by relational languages except when inserting new tuples) • No significance in ordering of tuples (unless sorting specified)
Keys K is a candidate key of relation R if it is a collection of attributes of R such that, independent of time, the following properties hold: • No two tuples of R have the same value of K. • If any attribute of K is dropped, then the uniqueness property is lost. Must select a CK to serve as the primary key. A superkey is a collection of attributes for which a subset of the attributes is a candidate key.
Database Schema A relational database schema S is a set of relation schemas S = {R1, R2, …, Rn} and a set of integrity constraints. IC – condition specified on d.b. schema that restricts data that can be stored in instance of d.b. A relational database instance DB of S is a set of relation instances DB = {r1, r2, …, rm} such that each ri is an instance of Ri and the ris satisfy the ICs.
Constraints Key constraints specify the CKs of each relation schema. A domain constraint specifies that the values that appear in a given column must be drawn from the domain for that column. The entity integrity constraint states that no PK can be null. The referential integrity constraint specifies that a tuple in one relation that refers to another relation must refer to an existing tuple in that relation.
Foreign Key A set of attributes FK in relation schema R1 is a foreign key of R1 if it satisfies the following: • The attributes in FK have the same domain as the primary key attributes PK of another relation schema R2; the attributes FK are said to reference or refer to the relation R2. • A value of FK in a tuple t1 of R1 either occurs as a value of PK for some tuple t2 in R2 or is null.