Professional Documents
Culture Documents
Database Lecture Notes Mapping ER Diagrams To Tables 1: Dr. Meg Murray Mcmurray@kennesaw - Edu
Database Lecture Notes Mapping ER Diagrams To Tables 1: Dr. Meg Murray Mcmurray@kennesaw - Edu
Attributes
Map to Columns
Identifiers
Map to Primary Keys
Relationships
Map to Foreign Keys
Relation
A relation is a two-dimensional table that has specific characteristics The table dimensions, like a matrix, consist of rows and columns
KROENKE and AUER - DATABASE CONCEPTS (3rd Edition) 2008 Pearson Prentice Hall
Characteristics of a Relation
Rows contain data about an entity Columns contain data about attributes of the entity Cells of the table hold a single value All entries in a column are of the same kind Each column has a unique name The order of the columns is unimportant The order of the rows is unimportant No two rows may be identical
KROENKE and AUER - DATABASE CONCEPTS (3rd Edition) 2008 Pearson Prentice Hall
A Sample Relation
EmployeeNumber 100 101 104 107 FirstName Mary Jerry Alex Megan LastName Abernathy Cadley Copley Jackson
KROENKE and AUER - DATABASE CONCEPTS (3rd Edition) 2008 Pearson Prentice Hall
A Nonrelation Example
Cells of the table hold multiple values EmployeeNumber Phone 100 335-6421, 454-9744 101 215-7789 104 610-9850 107 299-9090
KROENKE and AUER - DATABASE CONCEPTS (3rd Edition) 2008 Pearson Prentice Hall
A Nonrelation Example
No two rows may be identical
EmployeeNumber 100 101 104 100 107
KROENKE and AUER - DATABASE CONCEPTS (3rd Edition) 2008 Pearson Prentice Hall
Terminology
Synonyms Table File Relation Row Record Tuple Column Field Attribute
KROENKE and AUER - DATABASE CONCEPTS (3rd Edition) 2008 Pearson Prentice Hall
A Key
A key is one (or more) columns of a relation that is (are) used to identify a row
KROENKE and AUER - DATABASE CONCEPTS (3rd Edition) 2008 Pearson Prentice Hall
Uniqueness of Keys
Unique Key Data value is unique for each row. Consequently, the key will uniquely identify a row. Nonunique Key Data value may be shared among several rows. Consequently, the key will identify a set of rows.
KROENKE and AUER - DATABASE CONCEPTS (3rd Edition) 2008 Pearson Prentice Hall
A Composite Key
A composite key is a key that contains two or more attributes For a key to be unique, often it must become a composite key
KROENKE and AUER - DATABASE CONCEPTS (3rd Edition) 2008 Pearson Prentice Hall
KROENKE and AUER - DATABASE CONCEPTS (3rd Edition) 2008 Pearson Prentice Hall
A Candidate Key
A candidate key is called candidate because it is a candidate to become the primary key A candidate key is a unique key
KROENKE and AUER - DATABASE CONCEPTS (3rd Edition) 2008 Pearson Prentice Hall
A Primary Key
A primary key is a candidate key chosen to be the main key for the relation If you know the value of the primary key, you will be able to uniquely identify a single row
KROENKE and AUER - DATABASE CONCEPTS (3rd Edition) 2008 Pearson Prentice Hall
A Surrogate Key
A Surrogate Key is a unique, numeric value that is added to a relation to server as the Primary Key Surrogate Key values have no meaning to users and are usually hidden of forms, queries and reports A Surrogate Key is often used in place of a composite primary key
KROENKE and AUER - DATABASE CONCEPTS (3rd Edition) 2008 Pearson Prentice Hall
KROENKE and AUER - DATABASE CONCEPTS (3rd Edition) 2008 Pearson Prentice Hall
KROENKE and AUER - DATABASE CONCEPTS (3rd Edition) 2008 Pearson Prentice Hall
A Foreign Key
To preserve relationships, you may need to create a foreign key A foreign key is a primary key from one table placed into another table The key is called a foreign key in the table that received the key
KROENKE and AUER - DATABASE CONCEPTS (3rd Edition) 2008 Pearson Prentice Hall
Manager
MgrID MgrName
Foreign Key
ProjID ProjName
MgrID
KROENKE and AUER - DATABASE CONCEPTS (3rd Edition) 2008 Pearson Prentice Hall
Employee
EmpID DeptID
Foreign Key
DeptID DeptName
Location
EmpName
KROENKE and AUER - DATABASE CONCEPTS (3rd Edition) 2008 Pearson Prentice Hall
DAVID M. KROENKES DATABASE PROCESSING, 10th Edition 2006 Pearson Prentice Hall
6-21
[if you do not have italics, the foreign key is shown double underlined]
DAVID M. KROENKES DATABASE PROCESSING, 10th Edition 2006 Pearson Prentice Hall
3-22
KROENKE and AUER - DATABASE CONCEPTS (3rd Edition) 2008 Pearson Prentice Hall
KROENKE and AUER - DATABASE CONCEPTS (3rd Edition) 2008 Pearson Prentice Hall
DAVID M. KROENKES DATABASE PROCESSING, 10th Edition 2006 Pearson Prentice Hall
6-26
Surrogate Key
Supplied identifier generated by a DBMS
Assigned when a row is created They never change In simpler DBMS they are simply a sequential numbering scheme
Use if no good candidate for primary key Surrogate keys meet the ideal, but have no meaning to users
DAVID M. KROENKES DATABASE PROCESSING, 10th Edition 2006 Pearson Prentice Hall 6-27
Surrogate Key
In the ITEM table, ItemNumber is a surrogate key The data type of Identity shows this in this example it is SQL SERVER identifier
In the AKn.m notation, n is the number of the alternate key, and m is the column number in that alternate key
DAVID M. KROENKES DATABASE PROCESSING, 10th Edition 2006 Pearson Prentice Hall 6-30
Data Dictionary
Description of data objects - the meta data Usually presented in a table form with the following information:
Attribute name and table in which it is contained Data type Whether it can be null Whether it is a primary key Whether it is a foreign key
If so the corresponding table
DAVID M. KROENKES DATABASE PROCESSING, 10th Edition 2006 Pearson Prentice Hall
6-32
DAVID M. KROENKES DATABASE PROCESSING, 10th Edition 2006 Pearson Prentice Hall
6-33
DAVID M. KROENKES DATABASE PROCESSING, 10th Edition 2006 Pearson Prentice Hall
6-34
DAVID M. KROENKES DATABASE PROCESSING, 10th Edition 2006 Pearson Prentice Hall
6-35
DAVID M. KROENKES DATABASE PROCESSING, 10th Edition 2006 Pearson Prentice Hall
6-36
DAVID M. KROENKES DATABASE PROCESSING, 10th Edition 2006 Pearson Prentice Hall
6-37
VERIFY NORMALIZATION
DAVID M. KROENKES DATABASE PROCESSING, 10th Edition 2006 Pearson Prentice Hall
6-39
Normalization
We havent talked about this yet just note it is a check of efficiency of the tables created The tables should be normalized based on the data model
6-40