Top Banner
The Relational Model 1 Prof. Sin-Min Lee Department of Mathematics and Computer Science Prof. Sin-Min Lee Department of Computer Science
44

The Relational Model 1

Jan 14, 2016

Download

Documents

bynog bynog

Lecture 5. The Relational Model 1. Prof. Sin-Min Lee Department of Mathematics and Computer Science. Prof. Sin-Min Lee Department of Computer Science. History of Relational Model. First proposed by a E.F. Codd in 1970. Codd proposed the Relational model in 1970. - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: The Relational Model 1

The Relational Model 1

Prof. Sin-Min Lee

Department of Mathematics and Computer ScienceProf. Sin-Min Lee

Department of Computer Science

Page 2: The Relational Model 1

History of Relational Model

• First proposed by a E.F. Codd in 1970. Codd proposed the Relational model in 1970.“ A relational model of data for large shared data banks.”

•He linked the representation of data with that of mathematical sets.

• First research started at IBM’s San Jose Research Laboratory. Prototype was called System R.

• Commercial RDBMS’s started to appear in late 1970’s and early 1980’s. Most well known is Oracle.

Page 3: The Relational Model 1

Codd’s Original Paper

“A Relational Model of Data for Large Shared Data Banks”

Communications of the ACM, Volume 13, Number 6, June 1970

Lower level (basement) of the new Martin Luther King, Jr. Library

Get to roll the shelves apart to access journals.

Page 4: The Relational Model 1

Codd’s Reasons

Data independence from database implementation such as machine representation

Natural structure of data Can be analyzed mathematically (Codd was

a mathematician by training)

Page 5: The Relational Model 1

Alternative: Network Model

Charles A. Bachman 1973 ACM Turing Award Lecture “The Programmer as Navigator”

Communications of the ACM, Volume 16, Number 11, November 1973, pp. 653-657

Page 6: The Relational Model 1
Page 7: The Relational Model 1
Page 8: The Relational Model 1

Data Models

· Codd suggests that any data model has three components:

the data structures;

the integrity constraints;

the data manipulation operators.

Page 9: The Relational Model 1
Page 10: The Relational Model 1

Relational Data Structure

EMPLOYEEEmp# Name Emp Sex Mgr Emp#

E1 Jones Male E65

E6 Smith Male E28

E28 Jones Female -

Relation Attribute

Heading

Body

FemaleMale

Gender

Domain

Page 11: The Relational Model 1

The Domain

Emp#E1E2E3

NameRed

BrownBlack

Mgr#-

E1E1

E1, E2, E3,E4Red, BrownBlack, Blue

Attributes

Domains

Employee

Person Name

Emp#

Page 12: The Relational Model 1
Page 13: The Relational Model 1
Page 14: The Relational Model 1

Seven Characteristics of a relation

• The name of the relation is different from all others.

• Each cell of the relation contains only one value

• Each attribute (or field) has a name that is distinct.

• All the values of a particular attribute are from the same domain.

• The order of the attributes makes no difference.

• There are no duplicate tuples

• The order of the tuples makes no difference.

Page 15: The Relational Model 1

Example of the Student table.

SocialNum FirstName LastName PhoneNum Class#556-34-2832 John Smith 924-1000 32245

839-32-1929 Jane Doe 924-1929 99839

312-39-5193 Some Body 555-1000 11021

493-33-2910 Any One 555-1020 49303

Primary Key

Page 16: The Relational Model 1

Other terms...

Cardinality = Number of rows Degree = Number of columns

Cardinality = 6

Degree = 5

Page 17: The Relational Model 1
Page 18: The Relational Model 1
Page 19: The Relational Model 1
Page 20: The Relational Model 1
Page 21: The Relational Model 1
Page 22: The Relational Model 1
Page 23: The Relational Model 1
Page 24: The Relational Model 1

The Relational Data Model

· DATA STRUCTURES - domain, attribute, relation, tuple, primary key, degree, cardinality.

INTEGRITY CONSTRAINTS - entity integrity and referential integrity.

DATA MANIPULATION OPERATIONS - defined through relational algebra and equivalent relational calculus.

Page 25: The Relational Model 1

Entity Integrity

· No component of the Primary Key of a base relation is allowed to accept nulls.

SurnameRed

BlackRed

Black

Given NameJohn

Fred

Salary$40,000$50,000$60,000$70,000

Page 26: The Relational Model 1
Page 27: The Relational Model 1
Page 28: The Relational Model 1
Page 29: The Relational Model 1
Page 30: The Relational Model 1
Page 31: The Relational Model 1
Page 32: The Relational Model 1
Page 33: The Relational Model 1

Foreign Key· A foreign key is an attribute or attribute combination

of one relation R2 whose values are required to match those of the primary key of relation R1 where R1 and R2 are not necessarily distinct. Note that a foreign key and the corresponding primary key should be defined on the same domain(s).

Emp#e1e2e3

enameredblue

brown

Deptd1d2d3

Worksfordeptd1

d2

DnamePayTaxArt

Employee Dept

Foreign key

Page 34: The Relational Model 1

Referential Integrity

If base relation R2 includes a foreign key FK matching the primary key PK of some base relation R1 then every value of FK in R2 must either

(a) be equal to the value of PK in some tuple of R1, or

(b) be wholly null.

Note that PK and FK may comprise more than one attribute and that R1 and R2 are not necessarily distinct.

( Stated more simply a foreign key should be a valid primary key value or null.)

Page 35: The Relational Model 1

Foreign Key RulesFor each foreign key three rules need to be answered:

Can the foreign key accept nulls ?

What should happen on an attempt to delete the target of a foreign key reference?

What should happen on an attempt to update the target of a foreign key reference ?

Emp#e1e2e3

enameredblue

brown

Deptd1d2d3

Worksfordeptd1

d2

DnamePayTaxArt

Employee Dept

Page 36: The Relational Model 1

Foreign Key Rules

When should foreign key rules be checked ?

Dept (Dept#, Dname, Budget)

Emp (Emp#, Ename, Salary, WorksforDept#)

WorksforDept# References Dept delete cascades, update cascades

Depend (Emp#, Dependname, Date-of-birth)

Emp# references Emp delete cascades, update cascades

Page 37: The Relational Model 1

Example of the Class table.

Class# SectionNum Professor

32245 2 Lee

11021 1 Agoston

Primary Key

Page 38: The Relational Model 1

Class# SectionNum Professor

32245 2 Lee

11021 1 Agoston

SocialNum FirstName LastName PhoneNum Class#556-34-2832 John Smith 924-1000 32245

839-32-1929 Jane Doe 924-1929 99839

312-39-5193 Some Body 555-1000 11021

493-33-2910 Any One 555-1020 49303

Foreign key example

Page 39: The Relational Model 1

Relational instances in the Student relation

The content of the table (a grouping of rows) are called relational instances

These instances are unordered, and no two rows can be exactly alike

A relationalinstance

Page 40: The Relational Model 1

Integrity Constraints

All DBMS’ must have some form of ICs to prevent invalid data from being entered.

Domain constraints specify the set of values which may be used for each field.

Other constraints, such as key or tuple, may limit which values from the domain can be used for a given field in a given instance.

Key constraints require that each set of fields in the key be unique for each entry.

Page 41: The Relational Model 1

Enforcing Integrity Constraints

Each DBMS should have means to resolve invlaid entries such as: What happens if an entry that duplicates a key

entry is entered? What should be done if an entry of a foreign key

is deleted?A foreign key is a key where at least one field depends

on a field from a different table. What happens when an invalid entry is entered?

Page 42: The Relational Model 1

Relation schema Associated with each attribute is a set of

values, called a domain, that can be assigned to the entry of a tuple corresponding to the attribute.

A relation schema is a set of attributes. Example EMP = { Name, SSN,

DeptName, Salary, Birthdate } Convention

EMP(Name,SSN,DeptName,Salary,Birthdate)

Page 43: The Relational Model 1

IBM Relational Products

DB2 MVS/370 MVS/XASQL/DS VM/CMS DOS/VSEQMF front-end to DB2 and SQL/DSCSP application development tool

Numerous other RDBMS

ORACLE (SQL*Forms)INGRES from ASK Corp. (OSL,ABF)AIM/RDB from FujitsuINFORMIXVAXSQL/Rdb from DECNonStop SQL from Tandem

Relational DBMS Products

Microcomputer versions

ORACLEINGRESdBase IVmicroSQLpractically all micro DBMS

Page 44: The Relational Model 1

• The relational model is based on set operations. Tables are sets of rows. The actual storage structure is hidden from the user. The relational model is just concerned with a logical view of the data, not the physical view. There are no pointers for the user to worry about. The only data are explicit values in tables. All data values in the cells of tables are Atomic (also known as Scalar). Exactly one data value and not a set or a repeating group is allowed in each cell.

• Relational databases are the most widely used in the world ( 90+%.)

• A mathematical viewpoint helped to shape a database industry.

• Future? Possibly Object Oriented Database model.