Download presentation
Presentation is loading. Please wait.
Published byAlison Crawford Modified over 9 years ago
1
Relational Model E.F. Codd at IBM 1970 Chapter 3 (ed. 7 – Chap. 5)
2
Relational Model “A relational model of data for large shared data banks” Most popular simplest most uniform data structures most formal files + mathematical foundation
3
Example of a information in a database?
5
EMPLOYEEFNAMEMINITLNAMESSNBDATEADDRESSSEXSALARYSUPERSSNDNO John B Smith1234567891965-01-09731 Fondren, Houston, TXM30000333445555 5 Franklin T Wong3334455551955-12-08638 Voss, Houston, TXM40000888665555 5 Alicia J Zelaya9998877771968-01-193321 Castle, Spring, TXF25000987654321 4 Jennifer S Wallace9876543211941-06-20291 Berry, Bellaire, TXF43000888665555 4 Ramesh K Narayan6668844441962-09-15975 Fire Oak, Humble, TXM38000333445555 5 Joyce A English4534534531972-07-315631 Rice, Houston, TXF25000333445555 5 Ahmad V Jabbar9879879871969-03-29980 Dallas, Houston, TXM25000987654321 4 James E Borg8886655551937-11-10450 Stone, Houston, TXM55000null 1 DEPARTMENTDNAMEDNUMBERMGRSSNMGRSTARTDATE Research53334455551988-05-22 Administration49876543211995-01-01 Headquarters18886655551981-06-19
6
Database Object, instance, entity Relationships The relational model captures all of this in a table
7
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
8
Glossary of terms: Table -> RELATION Row -> TUPLE Column header -> ATTRIBUTE Data type of a column -> DOMAIN
10
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)
11
Relations RELATION Characteristics – Set of tuples - not ordered – Values within tuples are ordered ATTRIBUTES – A i is an attribute with a domain dom(A i ) – degree of a relation - the number of attributes RELATION SCHEMA: R(A 1, A 2,...,A n ): – includes relation name R and list (set) of attributes A i
12
DB Schema – 2 notations EMPLOYEE(Fname, Minit, Lname, SSN, Bdate, Address, Sex, Salary) EMPLOYEE Fname Minit Lname SSN Bdate Address Sex Salary
13
Relations RELATION (instance) r( R ) – current relation state – set of n-tuples (where n is a number of attributes) – r = {t 1, t 2,...,t m } each n-tuple t is an ordered list on n values – t = where v i is an element of dom(A i ) or null – t j [A i ] is the value v i for attribute A i of tuple t j – the tuples themselves are not ordered
14
r( R ) is a subset of what? (use domains of attributes) dom(A 1 ) X dom(A 2 ) X...X dom(A n )
15
Relations relation intension refers to the schema relation extension to the state all tuples within a relation are distinct
17
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
18
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 – t 1 [sk] != t 2 [sk] – every relation has at least one superkey, what is it?
19
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)
20
Constraints 3. ENTITY INTEGRITY CONSTRAINTS: – no primary key value can be null
21
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?
22
Referential Constraint - Relationships Student(Name, SSN, HomePhone, Address, OfficePhone, Age, GPA, Major) Department(Name, DeptHead, Location, College)
23
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. t 1 [PK] = t 2 [FK] Can a foreign key can be null? Yes, for example if an employee does not have a supervisor
24
Referential Constraint - Relationships Student(Name, SSN, HomePhone, Address, OfficePhone, Age, GPA, Major) Department(Name, DeptHead, Location, College)
25
Referential Constraint Name SSN HomePhone Address OfficePhone Age GPA Major Name DeptHead Location College
26
Relations RELATIONAL DATABASE SCHEMA – a set of relation schemas and a set of referential integrity constraints S = {R 1, R 2,..., R m } and a set of integrity constraints IC RELATIONAL DATABASE INSTANCE DB – DB = {r 1, r 2,...r m }
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.