View
224
Download
0
Category
Preview:
Citation preview
Relational Model E.F. Codd at IBM 1970
Chapter 3 (ed. 7 – Chap. 5)
Relational Model
• “A relational model of data for large shared data banks”
• Most popular• simplest • most uniform data structures • most formal• files + mathematical foundation
• Example of a information in a database?
EMPLOYEE FNAME MINIT LNAME SSN BDATE ADDRESS SEX SALARY SUPERSSN DNO
John B Smith 123456789 1965-01-09 731 Fondren, Houston, TX M 30000 333445555 5
Franklin T Wong 333445555 1955-12-08 638 Voss, Houston, TX M 40000 888665555 5
Alicia J Zelaya 999887777 1968-01-19 3321 Castle, Spring, TX F 25000 987654321 4
Jennifer S Wallace 987654321 1941-06-20 291 Berry, Bellaire, TX F 43000 888665555 4
Ramesh K Narayan 666884444 1962-09-15 975 Fire Oak, Humble, TX M 38000 333445555 5
Joyce A English 453453453 1972-07-31 5631 Rice, Houston, TX F 25000 333445555 5
Ahmad V Jabbar 987987987 1969-03-29 980 Dallas, Houston, TX M 25000 987654321 4
James E Borg 888665555 1937-11-10 450 Stone, Houston, TX M 55000 null 1
DEPARTMENT DNAME DNUMBER MGRSSN MGRSTARTDATE
Research 5 333445555 1988-05-22
Administration 4 987654321 1995-01-01
Headquarters 1 888665555 1981-06-19
Database
• Object, instance, entity• Relationships
• The relational model captures all of this in a table
Relational Model
• a table is composed of rows and columns• row - a collection of related data values
– describing an entity or relationship instance
• column – same attribute for different entities
• Relation is a table of values• Database is a collection of relations
Glossary of terms:
• Table -> RELATION• Row -> TUPLE• Column header -> ATTRIBUTE• Data type of a column -> DOMAIN
Glossary Cont’d
• DOMAIN D– specify data type, format for each domain– is of data-type (or format)– set of atomic values (relational model
requirement)• TUPLE
– no composite values (all values are atomic)– no multivalued attributes (First Normal Form)
Relations
• RELATION Characteristics – Set of tuples - not ordered– Values within tuples are ordered
• ATTRIBUTES– Ai is an attribute with a domain dom(Ai)– degree of a relation - the number of attributes
• RELATION SCHEMA: R(A1, A2,...,An):– includes relation name R and list (set) of attributes Ai
DB Schema – 2 notations
• EMPLOYEE(Fname, Minit, Lname, SSN, Bdate, Address, Sex, Salary)
• EMPLOYEE Fname Minit Lname SSN Bdate Address Sex Salary
Relations
• RELATION (instance) r( R )– current relation state – set of n-tuples (where n is a number of attributes)– r = {t1, t2,...,tm} each n-tuple t is an ordered list on n values
– t = <v1, v2,...vn> where vi is an element of dom(Ai) or null
– tj[Ai] is the value vi for attribute Ai of tuple tj
– the tuples themselves are not ordered
r( R ) is a subset of what? (use domains of attributes)
dom(A1) X dom(A2) X...X dom(An)
Relations
• relation intension refers to the schema• relation extension to the state• all tuples within a relation are distinct
Constraints
1. DOMAIN CONSTRAINTS:– 1st normal form 1NF
• value of each attribute must be an atomic (single) value from the domain for that attribute
• no composite attributes
Constraints
2. KEY CONSTRAINTS:– All elements are distinct
• no two tuples can have the same combination of values for all their values (uniqueness constraint). Therefore, all elements are distinct.
• How can this be enforced?• superkey sk
– any set of attributes with property: no two tuples from the relation have the same combination of
values for those attributes– t1[sk] != t2[sk]
– every relation has at least one superkey, what is it?
Constraints cont’d
• key is a minimal superkey if – we cannot remove any attribute and still have uniqueness
constraint hold– (city, state, zip)– Tuscaloosa has > 1 zip, same zip for Cottondale, Coaling
• candidate key is any one of the keys• primary key PK is designated candidate key
– underlined in both relation and ER models
• EMPLOYEE(Fname, Minit, Lname, SSN, Bdate, Address, Sex, Salary)
Constraints
3. ENTITY INTEGRITY CONSTRAINTS:– no primary key value can be null
Referential Constraint - Relationships
4. REFERENTIAL INTEGRITY CONSTRAINTS– a tuple in one relation that refers to another relation must
refer to an existing tuple in that relation
Student(Name, SSN, HomePhone, Address, OfficePhone, Age, GPA)Department(Name, DeptHead, Location, College)
• Students have a major• To Student relation add?
Referential Constraint - Relationships
Student(Name, SSN, HomePhone, Address, OfficePhone, Age, GPA, Major)Department(Name, DeptHead, Location, College)
Constraints
4. REFERENTIAL INTEGRITY CONSTRAINTS– a tuple in one relation that refers to another relation
must refer to an existing tuple in that relation• specified between two relations• maintain the consistency among tuples in two relations• if one relation refers another, then the primary key of the referred
relation is a foreign key FK in the referring relation. t1[PK] = t2[FK]
• Can a foreign key can be null?• Yes, for example if an employee does not have a supervisor
Referential Constraint - Relationships
Student(Name, SSN, HomePhone, Address, OfficePhone, Age, GPA, Major)
Department(Name, DeptHead, Location, College)
Referential Constraint
Name SSN HomePhone Address OfficePhone Age GPA Major
Name DeptHead Location College
Relations
• RELATIONAL DATABASE SCHEMA– a set of relation schemas and a set of referential integrity
constraints S = {R1, R2,..., Rm} and a set of integrity constraints IC
• RELATIONAL DATABASE INSTANCE DB– DB = {r1, r2,...rm}
Recommended