the relational database model cst272. return creating the unnormalized table n list the fields n...
TRANSCRIPT
The Relational Database Model
CST272
Return
Creating the Unnormalized Table
List the fields Select a primary key
– The field (or concatenation of two or more fields) that uniquely identifies each record
Purchase Order Report
Purchase Order (PO number, PO date, Vendor number, Vendor name, Address, City, State, ZIP code, Product number, Product, Unit price, Quantity, Extension, Subtotal, Tax, Shipping, Discount, PO total)
Unnormalized Table
Purchase Order Report
The Unnormalized Purchase Order Table
POnumber
POdate …
Productnumber Product … Subtotal …
10001 1/1/97 … 101103201
PencilsPensPaper
… 38.15 …
…
Purchase Order Report Return
To Convert from Unnormalized to 1NF Identify, list and remove repeating groups Modify Primary key (concatenated fields) Important: In 1NF there always will still
be just one table
Purchase Order (PO number, PO date, Vendor number, Vendor name, Address, City, State, ZIP code, Product number, Product, Unit price, Quantity, Subtotal, Tax, Shipping, Discount, PO total)
Repeating Groups
The Unnormalized Purchase Order TablePurchase Order Report
The Payables Table in 1NF
POnumber
POdate …
Productnumber Product … Subtotal …
10001 1/1/97 … 101 Pencils … 38.15 …10001 1/1/97 … 103 Pens … 38.15 …10001 1/1/97 … 201 Paper … 38.15 …
…
ReturnPurchase Order Report
Payables (PO number, PO date, Vendor number, Vendor name, Address, City, State, ZIP code, Product number, Product, Unit price, Quantity, Subtotal, Tax, Shipping, Discount, PO total)
1NF (First Normal Form)
Purchase Order Report The Payables Table in 1NF
To Convert from 1NF to 2NF
Identify the determinants– A listing of every possible combination of
elements (fields) that make up the 1NF primary key
Identify the functional dependencies– Which non-key fields rely on which
determinants to determine their value For the new 2NF tables, the determinants
are the primary keys
Payables (PO number, PO date, Vendor number, Vendor name, Address, City, State, ZIP code, Product number, Product, Unit price, Quantity, Subtotal, Tax, Shipping, Discount, PO total)
Determinants
PO number
Product number PO number, Product number
Functional Dependencies
Payables (PO number, PO date, Vendor number, Vendor name, Address, City, State, ZIP code, Product number, Product, Unit price, Quantity, Subtotal, Tax, Shipping, Discount, PO total)
Determinants
PO number PO date
Product number PO number, Product number
Functional Dependencies
Payables (PO number, PO date, Vendor number, Vendor name, Address, City, State, ZIP code, Product number, Product, Unit price, Quantity, Subtotal, Tax, Shipping, Discount, PO total)
Determinants
PO number PO date, Vendor number
Product number PO number, Product number
Functional Dependencies
Payables (PO number, PO date, Vendor number, Vendor name, Address, City, State, ZIP code, Product number, Product, Unit price, Quantity, Subtotal, Tax, Shipping, Discount, PO total)
Determinants
PO number PO date, Vendor number, Vendor name
Product number PO number, Product number
Functional Dependencies
Payables (PO number, PO date, Vendor number, Vendor name, Address, City, State, ZIP code, Product number, Product, Unit price, Quantity, Subtotal, Tax, Shipping, Discount, PO total)
Determinants
PO number PO date, Vendor number, Vendor name, Address
Product number PO number, Product number
Functional Dependencies
Payables (PO number, PO date, Vendor number, Vendor name, Address, City, State, ZIP code, Product number, Product, Unit price, Quantity, Subtotal, Tax, Shipping, Discount, PO total)
Determinants
PO number PO date, Vendor number, Vendor name, Address, City
Product number PO number, Product number
Functional Dependencies
Payables (PO number, PO date, Vendor number, Vendor name, Address, City, State, ZIP code, Product number, Product, Unit price, Quantity, Subtotal, Tax, Shipping, Discount, PO total)
Determinants
PO number PO date, Vendor number, Vendor name, Address, City, State
Product number PO number, Product number
Functional Dependencies
Payables (PO number, PO date, Vendor number, Vendor name, Address, City, State, ZIP code, Product number, Product, Unit price, Quantity, Subtotal, Tax, Shipping, Discount, PO total)
Determinants
PO number PO date, Vendor number, Vendor name, Address, City, State, ZIP code
Product number PO number, Product number
Functional Dependencies
Payables (PO number, PO date, Vendor number, Vendor name, Address, City, State, ZIP code, Product number, Product, Unit price, Quantity, Subtotal, Tax, Shipping, Discount, PO total)
Determinants
PO number PO date, Vendor number, Vendor name, Address, City, State, ZIP code
Product number Product
PO number, Product number
Functional Dependencies
Payables (PO number, PO date, Vendor number, Vendor name, Address, City, State, ZIP code, Product number, Product, Unit price, Quantity, Subtotal, Tax, Shipping, Discount, PO total)
Determinants
PO number PO date, Vendor number, Vendor name, Address, City, State, ZIP code
Product number Product
PO number, Product number Unit price
Functional Dependencies
Payables (PO number, PO date, Vendor number, Vendor name, Address, City, State, ZIP code, Product number, Product, Unit price, Quantity, Subtotal, Tax, Shipping, Discount, PO total)
Determinants
PO number PO date, Vendor number, Vendor name, Address, City, State, ZIP code
Product number Product
PO number, Product number Unit price, Quantity
Functional Dependencies
Payables (PO number, PO date, Vendor number, Vendor name, Address, City, State, ZIP code, Product number, Product, Unit price, Quantity, Subtotal, Tax, Shipping, Discount, PO total)
Determinants
PO number PO date, Vendor number, Vendor name, Address, City, State, ZIP code, Subtotal
Product number Product
PO number, Product number Unit price, Quantity
Functional Dependencies
Payables (PO number, PO date, Vendor number, Vendor name, Address, City, State, ZIP code, Product number, Product, Unit price, Quantity, Subtotal, Tax, Shipping, Discount, PO total)
Determinants
PO number PO date, Vendor number, Vendor name, Address, City, State, ZIP code, Subtotal, Tax
Product number Product
PO number, Product number Unit price, Quantity
Functional Dependencies
Payables (PO number, PO date, Vendor number, Vendor name, Address, City, State, ZIP code, Product number, Product, Unit price, Quantity, Subtotal, Tax, Shipping, Discount, PO total)
Determinants
PO number PO date, Vendor number, Vendor name, Address, City, State, ZIP code, Subtotal, Tax, Shipping
Product number Product
PO number, Product number Unit price, Quantity
Functional Dependencies
Payables (PO number, PO date, Vendor number, Vendor name, Address, City, State, ZIP code, Product number, Product, Unit price, Quantity, Subtotal, Tax, Shipping, Discount, PO total)
Determinants
PO number PO date, Vendor number, Vendor name, Address, City, State, ZIP code, Subtotal, Tax, Shipping, Discount
Product number Product
PO number, Product number Unit price, Quantity
Functional Dependencies
Payables (PO number, PO date, Vendor number, Vendor name, Address, City, State, ZIP code, Product number, Product, Unit price, Quantity, Subtotal, Tax, Shipping, Discount, PO total)
Determinants
PO number PO date, Vendor number, Vendor name, Address, City, State, ZIP code, Subtotal, Tax, Shipping, Discount, PO total
Product number Product
PO number, Product number Unit price, Quantity
Functional Dependencies
Purchase Order (PO number, PO date, Vendor number, Vendor name, Address, City, State, ZIP code, Subtotal, Tax, Shipping, Discount, PO total)
Payables (PO number, Product number, Unit price, Quantity)
Product (Product number, Product)
2NF (Second Normal Form)
Purchase Order Report
To Convert from 2NF to 3NF
Within the existing 2NF tables, identify the non-key determinants– Any non-key fields that could be a primary key
for other fields in one of the 2NF tables Identify those functional dependencies Create new table(s) from the determinant(s)
and functional dependency(cies) Do not remove the non-key determinant(s)
from original table(s)
Purchase Order (PO number, PO date, Vendor number, Vendor name, Address, City, State, ZIP code, Subtotal, Tax, Shipping, Discount, PO total)
Payables (PO number, Product number, Unit price, Quantity)
Product (Product number, Product)
Non-key Determinants
Purchase Order (PO number, PO date, Vendor number, Vendor name, Address, City, State, ZIP code, Subtotal, Tax, Shipping, Discount, PO total)
Payables (PO number, Product number, Unit price, Quantity)
Product (Product number, Product)
Vendor number
Non-key Determinants
Purchase Order (PO number, PO date, Vendor number, Vendor name, Address, City, State, ZIP code, Subtotal, Tax, Shipping, Discount, PO total)
Payables (PO number, Product number, Unit price, Quantity)
Product (Product number, Product)
Vendor number Vendor name
Non-key Determinants
Purchase Order (PO number, PO date, Vendor number, Vendor name, Address, City, State, ZIP code, Subtotal, Tax, Shipping, Discount, PO total)
Payables (PO number, Product number, Unit price, Quantity)
Product (Product number, Product)
Vendor number Vendor name, Address
Non-key Determinants
Purchase Order (PO number, PO date, Vendor number, Vendor name, Address, City, State, ZIP code, Subtotal, Tax, Shipping, Discount, PO total)
Payables (PO number, Product number, Unit price, Quantity)
Product (Product number, Product)
Vendor number Vendor name, Address, City
Non-key Determinants
Purchase Order (PO number, PO date, Vendor number, Vendor name, Address, City, State, ZIP code, Subtotal, Tax, Shipping, Discount, PO total)
Payables (PO number, Product number, Unit price, Quantity)
Product (Product number, Product)
Vendor number Vendor name, Address, City, State
Non-key Determinants
Purchase Order (PO number, PO date, Vendor number, Vendor name, Address, City, State, ZIP code, Subtotal, Tax, Shipping, Discount, PO total)
Payables (PO number, Product number, Unit price, Quantity)
Product (Product number, Product)
Vendor number Vendor name, Address, City, State, ZIP code
Non-key Determinants
Vendor (Vendor number, Vendor name, Address, City, State, ZIP code)
Purchase Order (PO number, Vendor number, Subtotal, Tax, Shipping, PO total, PO date)
Payables (PO number, Product number, Unit price, Quantity)
Product (Product number, Product)
3NF (Third Normal Form)
Finalize the Tables in Database Design Language Present the 3NF tables with all keys:
– Primary keys—that field which uniquely identifies (differentiates) a record from all other records in the table
– Alternate (secondary) keys—a field that could have been the primary key but is not; DBMS must enforce that values of field are unique for every record
– Foreign keys—a field that links to field values in another table; a foreign key value must match the primary key of one of the records in table to which it joins, or be null
Vendor (Vendor number, Vendor name, Address, City, State, ZIP code)
Purchase Order (PO number, Vendor number, Subtotal, Tax, Shipping, PO total, PO date)FK Vendor number Vendor
Payables (PO number, Product number, Unit price, Quantity)FK PO number Purchase OrderFK Product number Product
Product (Product number, Product)
DBDL (Database Design Language)
Vendor (Vendor number, Vendor name, Contact, Telephone)
Unnormalized—Contact Listing
Vendor (Vendor number, Vendor name, Contact, Telephone)
DBDL—Contact Listing
Merge the Tables
If you have two tables with the identical primary key, they generally should be merged into a single table
The results of each new normalization should be merged into the existing tables from previous normalizations
Vendor (Vendor number, Vendor name, Address, City, State, ZIP code, Contact, Telephone)
Purchase Order (PO number, Vendor number, Subtotal, Tax, Shipping, PO total, PO date)FK Vendor number Vendor
Payables (PO number, Product number, Unit price, Quantity)FK PO number Purchase OrderFK Product number Product
Product (Product number, Product)
DBDL—The Merged Tables
Vendor (Vendor number, Vendor name, Address, City, State, ZIP code, Contact, Telephone, Fax, Term days, Term percent, Date last order)
Purchase Order (PO number, Vendor number, Subtotal, Tax, Shipping, PO total, PO date, Bill date, Discount date, Due date)FK Vendor number Vendor
Payables (PO number, Product number, Unit price, Quantity, Back ordered?)FK PO number Purchase OrderFK Product number Product
Product (Product number, Product)
DBDL—The Final Tables
Mini Quiz
Normalize a “Student Transcript”using the model given from the “Payables” database
Student Transcript
Student ID: 345 Advisor ID: 56
Student Name: Sally Henson Advisor name: Ralph Pollard
Credits completed: 32 Advisor office: H203
Class standing: Freshman Advisor phone: 851-6590
Course number Grade
CS33 A
EG13 B+
1. Unnormalized table2. Repeating groups (list)3. 1NF4. Determinants and functional dependencies5. 2NF6. Non-key determinants and functional dependencies7. 3NF in DBDL (with all keys)
Return
The Unnormalized Table
Student (StudentID, StudentLast, StudentFirst, AdvisorID, AdvisorLast, AdvisorFirst, AdvisorOffice, AdvisorPhone, CreditsCompleted, ClassStanding, CourseNumber, Grade)– CreditsCompleted is the total credits currently completed
by the student– ClassStanding is Freshman, Sophomore, etc.– CourseNumber is each course (of more than one) that the
student has taken or is taking
Student Transcript
Convert from Unnormalized to 1NF
Identify, list and remove repeating groups Modify the unnormalized table by including
an additional field to create a concatenated primary key
Student Transcript
Repeating Groups
CourseNumber, Grade
Student Transcript
1NF
Student Grade (StudentID, StudentLast, StudentFirst, AdvisorID, AdvisorLast, AdvisorFirst, AdvisorOffice, AdvisorPhone, CreditsCompleted, ClassStanding, CourseNumber, Grade)
Student Transcript Return
Convert from 1NF to 2NF
Identify the determinants List the functional dependencies for each
determinant Create the new tables—one for each
determinant and the fields functionally dependent upon it
Determinants
StudentID CourseNumber StudentID, CourseNumber
1NF
Determinants and Functional Dependencies StudentID StudentLast, StudentFirst, AdvisorID,
AdvisorLast, AdvisorFirst, AdvisorOffice, AdvisorPhone, CreditsCompleted, ClassStanding
CourseNumber StudentID, CourseNumber Course Grade
1NF Return
2NF
Student (StudentID, StudentLast, StudentFirst, AdvisorID, AdvisorLast, AdvisorFirst, AdvisorOffice, AdvisorPhone, CreditsCompleted, ClassStanding
Course (CourseNumber) Student Course (StudentID, CourseNumber,
Grade)
Determinants Return
Convert from 2NF to 3NF
Identify any non-key determinants List the functional dependencies for each
non-key determinant Create any new tables—one for each non-
key determinant and the fields functionally dependent upon it
Non-key Determinants
AdvisorID
2NF
Non-key Determinants
AdvisorID AdvisorLast, AdvisorFirst, AdvisorOffice, AdvisorPhone
2NF Return
3NF
Student (StudentID, StudentLast, StudentFirst, AdvisorID, CreditsCompleted, ClassStanding
Advisor (AdvisorID, AdvisorLast, AdvisorFirst, AdvisorOffice, AdvisorPhone)
Course (CourseNumber) Student Course (StudentID, CourseNumber,
Grade)
ReturnNon-key Determinants
Finalize All Tables in DBDL
Identify all keys, both primary keys and foreign keys
DBDL
Student (StudentID, StudentLast, StudentFirst, AdvisorID, CreditsCompleted, ClassStanding
FK AdvisorID Advisor Advisor (AdvisorID, AdvisorLast, AdvisorFirst,
AdvisorOffice, AdvisorPhone Course (CourseNumber) Student Course (StudentID, CourseNumber,
Grade)
FK StudentID Student
FK CourseNumber Course3NF
Field Name Data Type SizeVendor number Text 5Vendor name Text 25Address Text 30City Text 15State Text 2ZIP code Text 10Telephone Text 14Contact Text 25Fax Text 14Term days Number IntegerTerm percent Number SingleDate last order Date/Time
The Vendor Table
Field Name Data Type SizeProduct number Text 3Product Text 20
The Product Table
Field Name Data Type SizePO number Text 5Vendor number Text 5Subtotal CurrencyTax CurrencyShipping CurrencyDiscount CurrencyPO total CurrencyPO date Date/TimeBill date Date/TimeDiscount date Date/TimeDue date Date/Time
The Purchase Order Table
Field Name Data Type SizePO number Text 5Product number Text 3Unit price CurrencyQuantity Number IntegerBack ordered? Yes/No
The Payables Table
Vendor Vendor ZIPnumber name Address City State code
20001 ACME UTILITIES 149 DIVISION STREET HICKSVILLE NY 1180120002 UNITED PETROLEUM 111 STATE STREET BRENTWOOD NY 1171720004 IBM 5601 NEW HIGHWAY POUGHKEEPSIE NY 12601
Term Term Date lastTelephone Contact Fax days percent order
(516) 938-0100 HOWARD (516) 938-0110 30 15 8/31/2004(516) 722-6929 ROCHELLE (800) 555-UPUP 0 0 10/15/2004(914) 261-6000 WILL (914) 261-6001 0 0 11/1/2004
The Vendor Data
Productnumber Product
101 PENCILS103 PENS110 MAGIC MARKERS201 PAPER301 PAPER WEIGHT501 RUBBER BANDS650 486 COMPUTER701 PENTIUM COMPUTER702 PENTIUM II COMPUTER900 DESK AND CHAIR
The Product Data
PO Vendor POnumber number Subtotal Tax Shipping Discount Total
10001 20001 38.15 3.24 3.00 0.01 44.3810002 20002 20.00 0.00 2.00 0.02 21.9810003 20001 551.75 0.00 3.00 0.03 554.7210004 20001 0.00 0.00 10.00 0.00 10.00
PO Bill Discount DueDate Date Date Date7/1/2004 7/30/2004 9/29/2004 11/30/2004
7/31/2004 9/10/2004 10/9/2004 10/9/200410/22/2004 11/5/200411/24/2004 11/24/2004
The Purchase Order Data
PO Product Unit Backnumber number price Quantity ordered?
10001 101 0.79 10 No10001 103 1.25 5 No10001 201 2.00 12 No10002 501 20.00 1 No10003 301 17.25 3 Yes10003 900 250.00 2 Yes
The Payables Data Use the mouse to click and placea in the field meaning "Yes"
or turn off meaning "No"
Use the mouse to click and placea in the field meaning "Yes"
or turn off meaning "No"
List the supplier company, supplier stock number and item name for all products in the inventory data base?
(Linked on common field between tables)
select Item, [Supplier stock number], [Company name]from Inventory, Supplierwhere Inventory.[Supplier code] = Supplier.[Supplier code];
Joining Two Tables Together
select Item, [Supplier stock number], [Company name] from Inventory, Supplier where Inventory.[Supplier code] = Supplier.[Supplier code];
Stock Item Supplier Supp09001 IBM PS/2 Model 30001 00610002 Using Wordstar 40003 00410050 80 Column IBM 90000 009
Supp Company name004 Acme Publishing006 Data Supplier009 CBS Record Sys
Item Supplier Supp Supp Company nameIBM PS/2 Model 30001 006 004 Acme PublishingUsing Wordstar 40003 004 004 Acme Publishing80 Column IBM 90000 009 004 Acme PublishingIBM PS/2 Model 30001 006 006 Data SuppliersUsing Wordstar 40003 004 006 Data Suppliers80 Column IBM 90000 009 006 Data SuppliersIBM PS/2 Model 30001 006 009 CBS Record SysUsing Wordstar 40003 004 009 CBS Record Sys80 Column IBM 90000 009 009 CBS Record Sys
select Item, [Supplier stock number], [Company name] from Inventory, Supplier ...;
Stock Item Supplier Supp09001 IBM PS/2 Model 30001 00610002 Using Wordstar 40003 00410050 80 Column IBM 90000 009
Supp Company name004 Acme Publishing006 Data Supplier009 CBS Record Sys
select Item, [Supplier stock number], [Company name] from Inventory, Supplier where Inventory.[Supplier code] = Supplier.[Supplier code];
Stock Item Supplier Supp09001 IBM PS/2 Model 30001 00610002 Using Wordstar 40003 00410050 80 Column IBM 90000 009
Supp Company name004 Acme Publishing006 Data Supplier009 CBS Record Sys
Item Supplier Supp Supp Company nameIBM PS/2 Model 30001 006 004 Acme PublishingUsing Wordstar 40003 004 004 Acme Publishing80 Column IBM 90000 009 004 Acme PublishingIBM PS/2 Model 30001 006 006 Data SuppliersUsing Wordstar 40003 004 006 Data Suppliers80 Column IBM 90000 009 006 Data SuppliersIBM PS/2 Model 30001 006 009 CBS Record SysUsing Wordstar 40003 004 009 CBS Record Sys80 Column IBM 90000 009 009 CBS Record Sys
select Item, [Supplier stock number], [Company name] from Inventory, Supplier where Inventory.[Supplier code] = Supplier.[Supplier code];
Item Supplier Supp Supp Company nameIBM PS/2 Model 30001 006 004 Acme PublishingUsing Wordstar 40003 004 004 Acme Publishing80 Column IBM 90000 009 004 Acme PublishingIBM PS/2 Model 30001 006 006 Data SuppliersUsing Wordstar 40003 004 006 Data Suppliers80 Column IBM 90000 009 006 Data SuppliersIBM PS/2 Model 30001 006 009 CBS Record SysUsing Wordstar 40003 004 009 CBS Record Sys80 Column IBM 90000 009 009 CBS Record Sys
Stock Item Supplier Supp09001 IBM PS/2 Model 30001 00610002 Using Wordstar 40003 00410050 80 Column IBM 90000 009
Supp Company name004 Acme Publishing006 Data Supplier009 CBS Record Sys
Stock Item Supplier Supp09001 IBM PS/2 Model 30001 00610002 Using Wordstar 40003 00410050 80 Column IBM 90000 009
Supp Company name004 Acme Publishing006 Data Supplier009 CBS Record Sys
select Item, [Supplier stock number], [Company name] from Inventory, Supplier where Inventory.[Supplier code] = Supplier.[Supplier code];
Item Supplier Supp Supp Company nameUsing Wordstar 40003 004 004 Acme PublishingIBM PS/2 Model 30001 006 006 Data Suppliers80 Column IBM 90000 009 009 CBS Record Sys
select Item, [Supplier stock number], [Company name] from Inventory, Supplier where Inventory.[Supplier code] = Supplier.[Supplier code];
Item Supplier Company nameUsing Wordstar 40003 Acme PublishingIBM PS/2 Model 30001 Data Suppliers80 Column IBM 90000 CBS Record Sys
Stock Item Supplier Supp09001 IBM PS/2 Model 30001 00610002 Using Wordstar 40003 00410050 80 Column IBM 90000 009
Supp Company name004 Acme Publishing006 Data Supplier009 CBS Record Sys