790 likes | 935 Views
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. Unnormalized Table.
E N D
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
Unnormalized Table 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) Purchase Order Report
The Unnormalized Purchase Order Table 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
Repeating Groups 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) The Unnormalized Purchase Order Table Purchase Order Report
The Payables Table in 1NF Purchase Order Report Return
1NF (First Normal Form) 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) The Payables Table in 1NF Purchase Order Report
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
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 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
2NF (Second Normal Form) 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) 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)
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)
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
3NF (Third Normal Form) 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)
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
DBDL (Database Design Language) 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 Order FK Product number Product Product (Product number, Product)
Unnormalized—Contact Listing Vendor (Vendor number, Vendor name, Contact, Telephone)
DBDL—Contact Listing Vendor (Vendor number, Vendor name, Contact, Telephone)
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
DBDL—The Merged Tables 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 Order FK Product number Product Product (Product number, Product)
DBDL—The Final 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 Order FK Product number Product Product (Product number, Product)
Unnormalized table Repeating groups (list) 1NF Determinants and functional dependencies 2NF Non-key determinants and functional dependencies 3NF in DBDL (with all keys) 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 numberGrade CS33 A EG13 B+ Return
The Unnormalized Table • Student(StudentID, StudentLast, StudentFirst, AdvisorID, AdvisorLast, AdvisorFirst, AdvisorOffice, AdvisorPhone, CreditsCompleted, ClassStanding, CourseNumber, Grade) • CreditsCompletedis 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