Presentation is loading. Please wait.

Presentation is loading. Please wait.

The Relational Database Model CST272. Return Creating the Unnormalized Table n List the fields n Select a primary key – The field (or concatenation of.

Similar presentations


Presentation on theme: "The Relational Database Model CST272. Return Creating the Unnormalized Table n List the fields n Select a primary key – The field (or concatenation of."— Presentation transcript:

1 The Relational Database Model CST272

2 Return

3 Creating the Unnormalized Table n List the fields n Select a primary key – The field (or concatenation of two or more fields) that uniquely identifies each record Purchase Order Report

4 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

5 The Unnormalized Purchase Order Table Purchase Order Report Return

6 To Convert from Unnormalized to 1NF n Identify, list and remove repeating groups n Modify Primary key (concatenated fields) n Important: In 1NF there always will still be just one table

7 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 Table Purchase Order Report

8 The Payables Table in 1NF Return Purchase Order Report

9 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

10 To Convert from 1NF to 2NF n Identify the determinants – A listing of every possible combination of elements (fields) that make up the 1NF primary key n Identify the functional dependencies – Which non-key fields rely on which determinants to determine their value n For the new 2NF tables, the determinants are the primary keys

11 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

12 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

13 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

14 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

15 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

16 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

17 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

18 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

19 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

20 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

21 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

22 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

23 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

24 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

25 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

26 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

27 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

28 To Convert from 2NF to 3NF n 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 n Identify those functional dependencies n Create new table(s) from the determinant(s) and functional dependency(cies) n Do not remove the non-key determinant(s) from original table(s)

29 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

30 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

31 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

32 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

33 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

34 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

35 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

36 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)

37 Finalize the Tables in Database Design Language n 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

38 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) DBDL (Database Design Language)

39

40 Vendor (Vendor number, Vendor name, Contact, Telephone) Unnormalized—Contact Listing

41 Vendor (Vendor number, Vendor name, Contact, Telephone) DBDL—Contact Listing

42 Merge the Tables n If you have two tables with the identical primary key, they generally should be merged into a single table n The results of each new normalization should be merged into the existing tables from previous normalizations

43 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 Merged Tables

44 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) DBDL—The Final Tables

45 Mini Quiz n Normalize a “Student Transcript”using the model given from the “Payables” database Student Transcript Student ID: 345Advisor ID: 56 Student Name: Sally HensonAdvisor name: Ralph Pollard Credits completed: 32Advisor office: H203 Class standing: FreshmanAdvisor phone: 851-6590 Course numberGrade CS33 A EG13 B+ 1.Unnormalized table 2.Repeating groups (list) 3.1NF 4.Determinants and functional dependencies 5.2NF 6.Non-key determinants and functional dependencies 7.3NF in DBDL (with all keys) 1.Unnormalized table 2.Repeating groups (list) 3.1NF 4.Determinants and functional dependencies 5.2NF 6.Non-key determinants and functional dependencies 7.3NF in DBDL (with all keys) Return

46 The Unnormalized Table n 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

47 Convert from Unnormalized to 1NF n Identify, list and remove repeating groups n Modify the unnormalized table by including an additional field to create a concatenated primary key Student Transcript

48 Repeating Groups n CourseNumber, Grade Student Transcript

49 1NF n Student Grade (StudentID, StudentLast, StudentFirst, AdvisorID, AdvisorLast, AdvisorFirst, AdvisorOffice, AdvisorPhone, CreditsCompleted, ClassStanding, CourseNumber, Grade) Student Transcript Return

50 Convert from 1NF to 2NF n Identify the determinants n List the functional dependencies for each determinant n Create the new tables—one for each determinant and the fields functionally dependent upon it

51 Determinants n StudentID  n CourseNumber  n StudentID, CourseNumber  1NF

52 Determinants and Functional Dependencies n StudentID  StudentLast, StudentFirst, AdvisorID, AdvisorLast, AdvisorFirst, AdvisorOffice, AdvisorPhone, CreditsCompleted, ClassStanding n CourseNumber  n StudentID, CourseNumber  Course Grade 1NF Return

53 2NF n Student (StudentID, StudentLast, StudentFirst, AdvisorID, AdvisorLast, AdvisorFirst, AdvisorOffice, AdvisorPhone, CreditsCompleted, ClassStanding n Course (CourseNumber) n Student Course (StudentID, CourseNumber, Grade) Determinants Return

54 Convert from 2NF to 3NF n Identify any non-key determinants n List the functional dependencies for each non-key determinant n Create any new tables—one for each non- key determinant and the fields functionally dependent upon it

55 Non-key Determinants n AdvisorID  2NF

56 Non-key Determinants n AdvisorID  AdvisorLast, AdvisorFirst, AdvisorOffice, AdvisorPhone 2NF Return

57 3NF n Student (StudentID, StudentLast, StudentFirst, AdvisorID, CreditsCompleted, ClassStanding n Advisor (AdvisorID, AdvisorLast, AdvisorFirst, AdvisorOffice, AdvisorPhone) n Course (CourseNumber) n Student Course (StudentID, CourseNumber, Grade) Return Non-key Determinants

58 Finalize All Tables in DBDL n Identify all keys, both primary keys and foreign keys

59 DBDL n Student (StudentID, StudentLast, StudentFirst, AdvisorID, CreditsCompleted, ClassStanding FK AdvisorID  Advisor n Advisor (AdvisorID, AdvisorLast, AdvisorFirst, AdvisorOffice, AdvisorPhone n Course (CourseNumber) n Student Course (StudentID, CourseNumber, Grade) FK StudentID  Student FK CourseNumber  Course 3NF

60

61 The Vendor Table

62 The Product Table

63 The Purchase Order Table

64 The Payables Table

65

66

67

68 The Vendor Data

69 The Product Data

70 The Purchase Order Data

71 The Payables Data Use the mouse to click and place a in the field meaning "Yes" or turn off meaning "No" Use the mouse to click and place a in the field meaning "Yes" or turn off meaning "No"

72

73 n List the supplier company, supplier stock number and item name for all products in the inventory data base? n (Linked on common field between tables) select Item, [Supplier stock number], [Company name] from Inventory, Supplier where Inventory.[Supplier code] = Supplier.[Supplier code]; Joining Two Tables Together

74 select Item, [Supplier stock number], [Company name] from Inventory, Supplier where Inventory.[Supplier code] = Supplier.[Supplier code];

75 select Item, [Supplier stock number], [Company name] from Inventory, Supplier...;

76 select Item, [Supplier stock number], [Company name] from Inventory, Supplier where Inventory.[Supplier code] = Supplier.[Supplier code];

77

78

79


Download ppt "The Relational Database Model CST272. Return Creating the Unnormalized Table n List the fields n Select a primary key – The field (or concatenation of."

Similar presentations


Ads by Google