The Relational Model CIS 218. Entity A Person, Place, Thing or Transaction Something the user wants...

Post on 20-Dec-2015

222 views 2 download

Transcript of The Relational Model CIS 218. Entity A Person, Place, Thing or Transaction Something the user wants...

The Relational Model

CIS 218

Entity

• A Person, Place, Thing or Transaction

• Something the user wants to track

Attribute

• A Property that describes an entity

• Also called a Field

Title

Author

Number of Pages

Subject

???

Attribute

• A Property that describes an entity

Identifier

• An attribute that names, or identifies, an entity instance

• May or may not be unique

Ludwig

Primary Key

• A unique identifier

Relation

• A relation is a two-dimensional table that has specific characteristics

2-7

Characteristics of a Relation

• Consists of columns and rows• Each row contains data about one entity• Each columns contains data about one attribute

of the entity• All entries in a column are of the same kind• Each cell of the table holds a single value• Each column has a unique name• No two rows may be identical

2-8

Is this a Relation?

2-9

EmployeeNumber Phone LastName

100 335-6421

454-9744

Abernathy

101 215-7789 Cadley

104 610-9850 Copley

107 299-9090 Jackson

Is this a Relation?

2-10

EmployeeNumber Phone LastName

100 335-6421 Abernathy

101 215-7789 Cadley

104 610-9850 Copley

100 335-6421 Abernathy

107 299-9090 Jackson

Is this a Relation?

2-11

EmployeeNumber

Phone Name Name

100 335-6421 Robin Abernathy

101 215-7789 Jessica Cadley

104 610-9850 Roger Copley

105 222-8873 Gurpreet Kaur

107 299-9090 Jazmyne Jackson

Is this a Relation?

2-12

EmployeeNumber

Phone Name Number

100 335-6421 Robin 123

101 215-7789 Jessica $27.45

104 610-9850 Roger Fourteen

105 222-8873 Gurpreet 37

107 299-9090 Jazmyne 5-06-65

Is this a Relation?

2-13

EmployeeNumber FirstName LastName

100 Mary Abernathy

101 Jerry Cadley

104 Alex Copley

107 Megan Jackson

A Composite Key

• A primary key made up of two or more attributes (columns)

• For a key to be unique, often it must become a composite key– Example: How would I look up a grade?

2-14

A Candidate Key

• A candidate to become the primary key• A unique identifier

– SID, SSN

2-15

A Surrogate Key

• A unique, numeric value that is added to a relation to serve as the Primary Key

• Has no meaning to users • Usually hidden in forms, queries and reports• In Access, uses an AutoNumber

2-16

Relationships

• Associations between entities

Relationships Between Tables

• A table may be related to other tables– An Employee is assigned to a Car– A Student takes a Class

• To relate tables, create a foreign key– Also called a linking column

• A foreign key is a primary key from one table placed into another table

2-18

Foreign Key Example

2-19

Project

ProjID

ProjName

MgrID

Manager

MgrID

MgrName

Foreign Key

Foreign Key Example

2-20

Department

DeptID

DeptName

Location

Employee

EmpID

DeptID

EmpName

Foreign Key

Foreign Key Example

2-21

Song

SongID

SongName

Time

Artist

ArtistID

ArtistName

Foreign KeyArtistID

Referential Integrity

• Every foreign key value must match a value of an existing primary key

• Therefore, the primary key value must exist before the foreign key value is entered

2-22

2-23

Referential Integrity

Each value of the Foreign Key OwnerID in PET

must exist in

The values of the Primary Key OwnerID in OWNER

2-24

Foreign Keys inMicrosoft Access

2-25