Professional Documents
Culture Documents
373 – Data Processing
Topics
I. Table Keys
Database Tables
II. Table Design Guidelines
Luis Guzman, University of Michigan 1
IOE 373 – Data Processing
Definition: A primary key is a column or set of For some entities, there may be more than one
columns that uniquely identifies each row in a field or collection of fields that can serve as the
table. primary key.
A key is a way to identify a particular record in a These are called candidate keys.
table. The primary key is a field, or collection of
fields, that allows for quick access to a record.
Luis Guzman, University of Michigan 2
IOE 373 – Data Processing
Luis Guzman, University of Michigan 3
IOE 373 – Data Processing
Luis Guzman, University of Michigan 4
IOE 373 – Data Processing
Luis Guzman, University of Michigan 5
IOE 373 – Data Processing
Luis Guzman, University of Michigan 6
IOE 373 – Data Processing
Luis Guzman, University of Michigan 7
IOE 373 – Data Processing
Luis Guzman, University of Michigan 8
IOE 373 – Data Processing
Luis Guzman, University of Michigan 9
IOE 373 – Data Processing
• As you can see, each table has exactly the same fields.
• The only thing separating the tables is the “Series” of the elements—
Actinides, NobleGases, Nonmetals, etc.
• By recognizing that Series is really just another attribute of elements, all of
these tables can be combined into one table containing all elements.
Luis Guzman, University of Michigan 10
IOE 373 – Data Processing
GOOD
EXAMPLE!
Luis Guzman, University of Michigan 11
IOE 373 – Data Processing
23 24
Luis Guzman, University of Michigan 12
IOE 373 – Data Processing
David Beckham’s wife decides to buy his team. Cuauhtémoc Blanco suffers a career-ending injury
You duly record this in his player record. playing for Mexico in the World Cup. ¡Qué lástima!
But now you have Landon Donovan and David Beckham You remove him from your MLS roster.
playing for the same team, but different owners! Oh-oh! You’ve removed all your information about
Your data is now inconsistent. the Chicago Fire team as well!
This is the update anomaly.
This is the delete anomaly.
25 26
Luis Guzman, University of Michigan 13
IOE 373 – Data Processing
27 28
Luis Guzman, University of Michigan 14
IOE 373 – Data Processing
29 30
Luis Guzman, University of Michigan 15
IOE 373 – Data Processing
31 32
Luis Guzman, University of Michigan 16
IOE 373 – Data Processing
33 34
Luis Guzman, University of Michigan 17
IOE 373 – Data Processing
35 36
Luis Guzman, University of Michigan 18
IOE 373 – Data Processing
Example: University
University: Solution
Luis Guzman, University of Michigan 19
IOE 373 – Data Processing
Issues:
If you don’t have different product codes for items that differ
only in color or size, those two attributes could be included in
OrderDetails instead.
Where should each non-key field go? Similarly, Cost depends on whether you have fixed prices (in
which case cost belongs with Products), or if your prices change
with time or if certain customers or orders get discounts.
Luis Guzman, University of Michigan 20
IOE 373 – Data Processing
Luis Guzman, University of Michigan 21
IOE 373 – Data Processing
Example Solution
Employees
empID lastName firstName deptNum deptName
1001 Smith John 2 Marketing Employees Departments
1005 Jones Susan 2 Marketing empID lastName firstName deptNum deptNum deptName
1029 Li Jane 1 Sales 1001 Smith John 2 1 Sales
1005 Jones Susan 2 2 Marketing
Luis Guzman, University of Michigan 22
IOE 373 – Data Processing
Every non-key field in a table Every entity should have a primary key (1NF)
Every attribute should depend on the entire
should depend on
Luis Guzman, University of Michigan 23