Presentation is loading. Please wait.

Presentation is loading. Please wait.

McGraw-Hill/Irwin Copyright © 2005 by The McGraw-Hill Companies, Inc. All rights reserved. ENTERPRISE INFORMATION SYSTEMS A PATTERN BASED APPROACH Chapter.

Similar presentations


Presentation on theme: "McGraw-Hill/Irwin Copyright © 2005 by The McGraw-Hill Companies, Inc. All rights reserved. ENTERPRISE INFORMATION SYSTEMS A PATTERN BASED APPROACH Chapter."— Presentation transcript:

1 McGraw-Hill/Irwin Copyright © 2005 by The McGraw-Hill Companies, Inc. All rights reserved. ENTERPRISE INFORMATION SYSTEMS A PATTERN BASED APPROACH Chapter 6 Relational Database Design: Converting Conceptual Models to Relational Databases

2 6-2 Chapter Learning Objectives 1.Convert a conceptual business process level REA model into a logical relational model 2.Convert a logical relational model into a physical implementation using Microsoft Access 3.Explain the difference between conceptual, logical, and physical database models 4.Enter transaction data into a relational database 5.Interpret a physical database implementation in Microsoft Access to determine what must have been the underlying logical model 6.Interpret a logical relational model to determine what the underlying conceptual model must have been 7.Recognize and implement various application level controls to facilitate the integrity of data entered into a relational database

3 6-3 Database Model Levels A Conceptual model represents reality in an abstracted form that can be used in developing an information system in a wide variety of formats (e.g. relational, object-oriented, flat-file, etc.) –It is hardware and software independent –It is independent of any logical model type A Logical model represents reality in the format required by a particular database model (e.g. relational or object-oriented) –Is still hardware and software independent –Depends on the chosen logical model type A Physical model is created specifically for a particular database software package –Is dependent on hardware, software, and on the chosen logical model type

4 6-4 Relational Database Model The relational model is a type of logical database model that was conceived by E.F. Codd in 1969 The relational model is based on set theory and predicate logic –It is well formalized, so its behavior is predictable A relational database consists of tables (relations) that are linked together via the use of primary and foreign keys –A FOREIGN KEY in a table is a primary key from a different table that has been posted into the table to create a link between the two tables

5 6-5 Relational Database Model Relational database tables are made up of rows and columns –Rows are called the table extension or tuples The ordering of rows in a table does not matter –Columns are called the table intension or schema The ordering of columns in a table does not matter All values in a column must conform to the same data format (e.g. date, text, currency, etc.) –Each cell in a database table (a row-column intersection) can contain only one value no repeating groups are allowed

6 6-6 Foreign Key Example SalespersonIDName 123456Fred 654321Francis SaleIDDateAmountSalesperson 061401A6/14$4,218123456 061401B6/14$6,437654321 061501A6/15$1,112654321

7 6-7 Relational Database Model Some principles of the relational model –Entity Integrity A primary key in a table must not contain a null value –Guarantees uniqueness of entities and enables proper referencing of primary key values by foreign key values –Referential Integrity A value for a foreign key in a table must either –Be null (blank) –Match exactly a value for the primary key in the table from which it was posted –One Fact, One Place Fact = a pairing of a candidate key attribute value with another attribute value –Facts are found in the extensional data

8 6-8 Referential Integrity Example

9 6-9 One Fact-One Place Violations One fact in multiple places 1 1 2 2 3 3 4 4

10 6-10 One Fact-One Place Violations Multiple facts in one place 1 2 3 45 Each value of each attribute in a row is paired with the primary key, so if any cell has two or more attribute values, by definition there are multiple facts in one place (also known as a repeating group)

11 6-11 Converting Conceptual to Relational Step 1: Create a separate table to represent each entity in the conceptual model –1A: Each attribute of the entity becomes a column in the relational table –2A: Each instance (member) of the entity set will become a row in the relational table Steps 2-4 (detailed in the next few slides) involve determining whether each relationship in the conceptual model should be represented as a separate table or as a posted foreign key –Redundancy and Load are important determinants Redundancy = one fact in multiple places or multiple facts in one place Load = the percentage of non-null values in a column –Participation Cardinalities communicate some of the information regarding redundancy and load

12 6-12 Relationship Conversion Maximum Cardinalities –The general rule is to post into a 1 entity table This avoids repeating groups redundancy –You can NEVER post into an N entity This causes repeating groups redundancy Minimum Cardinalities –The general rule is to post into a 1 (mandatory) entity table This avoids null values in the foreign key column –This rule should be violated in some circumstances (to be discussed soon)

13 6-13 Step 2: Create a separate table to represent each many-to-many relationship in the conceptual model, I.e., for the following participation cardinality patterns (0,N)-(0,N) (0,N)-(1,N) (1,N)-(0,N) (1,N)-(1,N) –You must create a separate table to represent the relationship The primary keys of the related entity tables are posted into the relationship table to form its primary key. This kind of primary key is called a composite or concatenated primary key This avoids redundancy There are no exceptions to this rule!!! –If you post a foreign key in either direction, redundancy will be a problem for many-to-many relationships Relationship Conversion

14 6-14 Example: Many-Many Relationships Student#NameAddress 1TonyCleveland 2EmilyNew York 3LeighBirmingham Course#Name Acg4401AIS Acg3101FAR 1 Course# * Acg4401, Acg3101 Student#* 1, 2, 3

15 6-15 Example: Many-Many Relationship Student#NameAddress 1TonyCleveland 2EmilyNew York 3LeighBirmingham Course#Name Acg4401AIS Acg3101FAR 1 Student#Course# 1Acg4401 1Acg3101 2Acg4401 2Acg3101 3

16 6-16 Relationship Conversion Step 3: For participation cardinality pattern (1,1)-(1,1), consider whether the two entities are conceptually separate or whether they should be combined –If they should remain separate, then 3A: Post the primary key from one entitys table into the other entitys table as a foreign key 3B: It doesnt matter which entitys primary key is posted into the other entitys table, but DO NOT post both –DO NOT make a separate table –Redundancy is automatically avoided and load is not an issue when you post a foreign key into either table in a (1,1)-(1,1) relationship

17 6-17 Example: (1,1)-(1,1) SaleIDDateAmount S16/12$10 S26/12$15 S36/13$12 CR-IDDateAmount CR16/12$10 CR26/12$15 CR36/13$12 CR-ID * CR1 CR2 CR3 S-ID * S1 S2 S3 Choose ONE of these; DO NOT do both!!! Sale Cash Receipt yields (1,1) SaleID Date Amount CR-ID Date Amount

18 6-18 Relationship Conversion Step 4: For remaining relationships that have (1,1) participation by one entity set, post the related entitys primary key into the (1,1) entitys table as a foreign key –I.e., for the following participation cardinality patterns (0,N)-(1,1) (1,N)-(1,1) (1,1)-(0,N) (1,1)-(1,N) (0,1)-(1,1) (1,1)-(0,1) Do NOT make a separate table Post a foreign key INTO the (1,1) entitys table from the other entitys table Redundancy is avoided and load is not an issue if you follow this instruction If you post the opposite direction, either redundancy [for N maximums] OR load [for 0 minimums] will be a problem

19 6-19 Example 1: Posting into a (1,1) Sale Customer Is-to (1,1) (0,N) SaleID Date Amount CustID Name City (1,N) or SaleIDDateAmount S16/12$10 S26/12$15 S36/13$12 CincinnatiStevenC2 Walnut CreekHeatherC1 AddressNameCust-ID Cust-ID* C1 C2 C1 C3DaveCincinnati S2 S1, S3 S-ID*

20 6-20 Example 2: Posting into a (1,1) Sale Cash Receipt yields (1,1) (0,1) SaleID Date Amount CR-ID Date Amount SaleIDDateAmount S16/12$10 S26/12$15 S36/13$12 CR-IDDateAmount CR16/12$10 CR26/12$15 CR36/13$12 CR46/13$1,000 CR-ID* CR1 CR2 CR3 S-ID* S1 S2 S3

21 6-21 Relationship Conversion Step 5: For remaining relationships that have (0,1) participation by one or both of the entities, consider load I.e., for the following participation cardinality patterns (0,N)-(0,1) (1,N)-(0,1) (0,1)-(0,N) (0,1)-(1,N) (0,1)-(0,1) –The rule for maximum cards requires posting into a (0,1) or making a separate table; you CANNOT post into the (0,N) or (1,N) –The rule for minimum cards says you really shouldnt post into the (0,1) because it will create null values that waste valuable space in the database However, if a separate table would waste more space, then it is better to follow the maximum rule and break the minimum rule –5A: Post the related entitys primary key into the (0,1) entitys table as a foreign key for any relationships for which that results in a high load –5B: Create a separate table for any relationships for which posting a foreign key results in low load Note: For (0,1)-(0,1), step 5A, post whichever direction results in highest load; if neither direction yields high load, then follow step 5B

22 6-22 Example: Load Considerations Some cash disbursements (13/26) pay for purchases –If we post Receiving Report# into Cash Disbursement, 13 out of 26 will be non-null –This is a medium load –Might be worth breaking minimum rule –Consider other posting option Most purchases (14/18) result in cash disbursements –If we post Check# into Purchase, 14 out of 18 will be non-null –This is a high load –Worth breaking the minimum rule Conclusion: post Check# into Purchase table to represent the pays for relationship

23 6-23 Example: Load considerations Few purchases (3/18) result in purchase returns –If we post Purchase Return Slip# into Purchase, only 3 out of 18 will be non-null –This is low load –Must either make a separate table or consider posting the other direction Cant post receiving report# into purchase return because one purchase return slip # can be associated with multiple purchases Conclusion: Make a separate table to represent the allowance for relationship

24 6-24 Relationship Attribute Placement If relationship becomes a separate table, then relationship attributes are placed in that table If relationship can be represented by a posted foreign key, relationship attribute is posted alongside the foreign key

25 6-25 Relationship Attribute Placement If relationship becomes a separate table, then relationship attributes are placed in that table If relationship can be represented by a posted foreign key, relationship attribute is posted alongside the foreign key

26 6-26 Fixing One Fact Multiple Places What facts are in multiple places in this table? Reverse engineer to get the ER model that this table must represent Is the ER model that results in this table correct? What SHOULD the ER model have been instead? What is the correct relational model? EmpIDEmpNamePayrateHours WorkedDept#DeptName 8532Andy$1336D423Audit 7352Jennifer$1445D423Audit 215Arlie$2050D777ISAAS 4332Craig$1860D821Tax 74Steven$2264D821Tax Employee

27 6-27 Fixing One Fact Multiple Places Employee Department Assigned to EmplID Empname HoursWorked Payrate DeptID DeptName EmpIDEmpNamePayrateHours WorkedDept# 8532Andy$1336D423 7352Jennifer$1445D423 215Arlie$2050D777 4332Craig$1860D821 74Steven$2264D821 Dept#DeptName D423Audit D777ISAAS D821Tax Employee Department

28 6-28 Fixing Multiple Facts in One Place What facts are in multiple places? How could this be avoided? Warehouse#AddressQOH W1123 Oak2,14,784 W2456 Pine4,23,873 Product#DescriptionStdCostQOH AB12Granddaddy$5,0002,4 BC445Mama$3,00014,23 DD2Littlebabe$100784,873 Warehouse#Product# W1AB12 W1BC445 W1DD2 W2AB12 W2BC445 W2DD2 Inventory Warehouse InventoryInWarehouse

29 6-29 Fixing Multiple Facts in One Place Warehouse#Address W1123 Oak W2456 Pine Product#DescriptionStdCost AB12Granddaddy$5,000 BC445Mama$3,000 DD2Littlebabe$100 Warehouse#Product#QOH W1AB122 W1BC44514 W1DD2784 W2AB124 W2BC44523 W2DD2873 Inventory Warehouse InventoryInWarehouse

30 6-30 Physical Implementation using Microsoft Access

31 6-31 Creating an Access Database

32 6-32 Creating Access Tables

33 6-33 Connecting Access Tables

34 6-34 Concatenated Primary Keys

35 6-35 Relationships between tables versus relationships between entities

36 6-36 Relational Database Design Summary The relational model is based on set theory and predicate logic and the resultant relations (tables) can be manipulated for information retrieval purposes if they are properly constructed To create well-behaved tables, follow the rules we discussed –Conversion rules for cardinality patterns –One Fact-One Place Think at the data (extensional) level!! When creating physical databases, use the conceptual and logical models to help you realize the important issues and potential pitfalls

37 McGraw-Hill/Irwin Copyright © 2005 by The McGraw-Hill Companies, Inc. All rights reserved. ENTERPRISE INFORMATION SYSTEMS A PATTERN BASED APPROACH Chapter 6 End of Chapter


Download ppt "McGraw-Hill/Irwin Copyright © 2005 by The McGraw-Hill Companies, Inc. All rights reserved. ENTERPRISE INFORMATION SYSTEMS A PATTERN BASED APPROACH Chapter."

Similar presentations


Ads by Google