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 EmployeeNumberPhoneLastName Abernathy Cadley Copley Jackson
Is this a Relation? 2-10 EmployeeNumberPhoneLastName Abernathy Cadley Copley Abernathy Jackson
Is this a Relation? 2-11 Employee Number PhoneName RobinAbernathy JessicaCadley RogerCopley GurpreetKaur JazmyneJackson
Is this a Relation? 2-12 Employee Number PhoneNameNumber Robin Jessica$ RogerFourteen Gurpreet Jazmyne
Is this a Relation? 2-13 EmployeeNumberFirstNameLastName 100MaryAbernathy 101JerryCadley 104AlexCopley 107MeganJackson
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 Key ArtistID
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 in Microsoft Access 2-25