Chapter 18 Implementing an REA Model in a Relational Database 18-1.
-
Upload
cameron-brooks -
Category
Documents
-
view
267 -
download
4
Transcript of Chapter 18 Implementing an REA Model in a Relational Database 18-1.
Chapter 18Implementing an REA Model in a Relational Database
18-1
18-2
Intergraded REA Diagram
Rules for Creating Integrated REA Diagram
1. Every event must be linked to at least one resource.
2. Every event must be linked to two agents who participate in that event.
3. Every event that involves the disposition of a resource must be linked to an event that involves the acquisition of a resource.
4. Every resource must be linked to at least one event that increments that resource and to at least one event that decrements that resource.
5. If event A can be linked to more than one other event, but cannot be linked simultaneously to all of those other events, then the REA diagram should show that event A is linked to a minimum of 0 of each of those other events.
18-3
Using REA Diagram to Create Relational Database
Advantage: Creating a set of tables from an REA
diagram automatically results in a well-structured relational database
Ensures the elimination of anomalies: Update Insert Delete
18-4
REA to Database Steps1. Create a table for each distinct entity in
the diagram and for each many-to-many relationship.
2. Assign attributes to appropriate tables. Identify primary keys:
Attributes that uniquely identifies each record.
For M:N relationships the primary key consists of two attributes that represent the primary keys of each entity linked in that relationship.
Identify remaining attributes for table.
3. Use foreign keys to implement one-to-one and one-to-many relationships.
An attribute of one entity that is itself the primary key of another entity. 18-5
• Our integrated diagram has seven event entities.
1
2
3
4
5
6
7
• Our integrated diagram has two resource entities.
1
2
1
12
2
3
3
3
3
3
3
• There are three distinct agent entities.• The first is the customer.• The second agent entity is the supplier.• The third agent entity is the employee. We label the types of
employees to make the diagram more understandable, but they all go in one table.
IMPLEMENTING AN REA DIAGRAM IN A RELATIONAL DATABASE
Total distinct entities to be represented in separate tables:
9
Table Types # Events 8Resources 2Agents 3Distinct Entities 12
7
IMPLEMENTING AN REA DIAGRAM IN A RELATIONAL DATABASE
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
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 10
Example: Many-Many Relationships(from DCH)
STUDENT COURSETAKES
(1,N) (1,N)
student #
name
address
course #
name
Student# Name Address
1 Tony Cleveland
2 Emily New York
3 Leigh Birmingham
Course# Name
Acg4401 AIS
Acg3101 FAR 1
Course# *
Acg4401, Acg3101
Acg4401, Acg3101
Acg4401, Acg3101
Student#*
1, 2, 3
1, 2, 3
11
Note: Each record field must be single valued(no repeating groups)
Example: Many-Many Relationship(from DCH)
STUDENT COURSETAKES
(1,N) (1,N)
student #
name
address
course #
name
Student# Name Address
1 Tony Cleveland
2 Emily New York
3 Leigh Birmingham
Course# Name
Acg4401 AIS
Acg3101 FAR 1
Student# Course#
1 Acg4401
1 Acg3101
2 Acg4401
2 Acg3101
3 Acg3101
Student-Course Relationship Table
12
• the many-to-many relationships.
1
2
3
4
5
IMPLEMENTING AN REA DIAGRAM IN A RELATIONAL DATABASE
Total number of tables in database:
Table Types #
Events 7
Resources 2
Agents 3
Distinct Entities 12
Many to many Tables 5
Total Tables 17
14
IMPLEMENTING AN REA DIAGRAM IN A RELATIONAL DATABASE
Identify primary keys Every table in a relational database must
have a primary key. The primary key is an attribute or
combination of attributes that uniquely identifies each row in a table.
It is typically a numeric identifier. The primary key is usually a single
attribute. However for M:N relationship tables, it
consists of two attributes that represent the primary key of each linked entity. These multiple-attribute primary keys
are called concatenated keys.
18-16
SALES
CASH RECEIPT
EMPLOYEESALES REP
CUSTOMER
EMPLOYEECASHIER
INVENTORY
CASH
Duality
Partic-ipation 3
Partic-ipation 4
Partic-ipation 5
Partic-ipation 6
Stockflow 1
Stockflow 2
Fred's Train Shop Revenue Cycle
(0,N)
(0,N) (0,N)
(0,N)
(0,N)
(0,N)
(1,1)
(1,1)
(0,1)
(0,N)
(0,N)
(1,1) (1,1)
(1,N)
Sale Order CUSTOMERPartic-ipation 1
Partic-ipation 2
(0,N)
(0,N)
(0,N)
(1,N)
(1,1)
(1,1)
(0,1)
(0,1)
C-Acct# C-BalType RA# TimeDate Pmt method
Emp# DOBDateHired
Pay Rate
Job Title
Cust# Cname CreditLimit
EmpName
Address
AcctBalanceDateSO# Time Comments
Date
Inv#
Time InvSent(Y/N)
Prod# DescList-Price
Std-cost
QOH QAvai
Reorder-Qty
Reorder-Pt
Qty Ordered
Qty Sold
Actual SalePrice
Amopunt Applied to
Invoice
Attribute assignment
17
AttributesTables Primary key Foreign Key(s) Other Attributes
SaleOrder SaleOrder# Date, Time, Comments
Sale Invoice# Date, Time, InvoiceSent(Y/N)
CashReceipt RA# Date, Time, PmtMethod
Inventory Product#Desc, ListPrice, StdCost, QtyonHand, QtyAvailable, ReorderQty, ReorderPoint
Cash Account # BegBalance, AcctType
Emoloyee Employee#EmpName, DateHired, DateBirth, PayRate, JobTitle
Customer Customer#Custname, Address, AccountBalance, CreditLimit
SaleOrder-InventorySaleOrder#, Product#
Sale-InventoryInvoice#, Product#
Sale-CashReceipt Invoice#, RA#
Tables for Fred’s Train
Shop Revenue
cycle
Use foreign keys to implement one-to-one and one-to-many relationships. Minimum cardinalities may suggest which
choice is more efficient. When there are two sequential events,
the primary key of the event that occurs first is usually the foreign key in the event that occurs second.
The primary key of the entity that can linked to multiple instances of the other entity must become the foreign key in that other entity. Example: The primary key for customer
(which can occur only once per sale) is a foreign key in the sales table (which can occur many times for a particular customer).
18
Example: (1,1)-(1,1)
SaleID Date Amount
S1 6/12 $10
S2 6/12 $15
S3 6/13 $12
CR-ID Date Amount
CR1 6/12 $10
CR2 6/12 $15
CR3 6/13 $12
CR-ID *
CR1
CR2
CR3
S-ID *
S1
S2
S3
Could do either one but because the entities represent sequential events, authors follow the practice of placing the primary key of the event that occurs first (sale) as a foreign key in the event that occurs second (cash receipt).
Sale Cash Receipt
yields(1,1) (1,1)
SaleID Date Amount CR-ID Date Amount
20
Example 2: Posting into a (1,1)-(0,1)
Sale Cash Receipt
yields
(1,1) (0,1)
SaleID Date Amount CR-ID Date Amount
SaleID Date Amount
S1 6/12 $10
S2 6/12 $15
S3 6/13 $12
CR-ID Date Amount
CR1 6/12 $10
CR2 6/12 $15
CR3 6/13 $12
CR4 6/13 $1,000
CR-ID*
CR1
CR2
CR3
S-ID*
S1
S2
S3
This eliminates null values
Example : Posting into a one to many
Sale CustomerIs-to
(1,1) (0,N)
SaleID Date Amount CustID NameCity
SaleID Date Amount
S1 6/12 $10
S2 6/12 $15
S3 6/13 $12
CincinnatiStevenC2
Walnut CreekHeatherC1
AddressNameCust-ID
Cust-ID*
C1
C2
C1
C3 Dave Cincinnati
S2
S1, S3
S-ID*
SALES
CASH RECEIPT
EMPLOYEESALES REP
CUSTOMER
EMPLOYEECASHIER
INVENTORY
CASH
Duality
Partic-ipation 3
Partic-ipation 4
Partic-ipation 5
Partic-ipation 6
Stockflow 1
Stockflow 2
Fred's Train Shop Revenue Cycle
(0,N)
(0,N) (0,N)
(0,N)
(0,N)
(0,N)
(1,1)
(1,1)
(0,1)
(0,N)
(0,N)
(1,1) (1,1)
(1,N)
Sale Order CUSTOMERPartic-ipation 1
Partic-ipation 2
(0,N)
(0,N)
(0,N)
(1,N)
(1,1)
(1,1)
(0,1)
(0,1)
C-Acct# C-BalType RA# TimeDate Pmt method
Emp# DOBDateHired
Pay Rate
Job Title
Cust# Cname CreditLimit
EmpName
Address
AcctBalanceDateSO# Time Comments
Date
Inv#
Time InvSent(Y/N)
Prod# DescList-Price
Std-cost
QOH QAvai
Reorder-Qty
Reorder-Pt
Qty Ordered
Qty Sold
Actual SalePrice
Amopunt Applied to
Invoice
18-22
Use foreign keys to implement one-to-one and one-to-many relationships
18-23
AttributesTables Primary key Foreign Key(s) Other Attributes
SaleOrder SaleOrder#Customer#, Employee#
Date, Time, Comments
Sale Invoice#SaleOrder#, Customer#, Employee#
Date, Time, InvoiceSent(Y/N)
CashReceipt RA#Customer#, Employee#, Account#
Date, Time, PmtMethod
Inventory Product#Desc, ListPrice, StdCost, QtyonHand, QtyAvailable, ReorderQty, ReorderPoint
Cash Account # BegBalance, AcctType
Emoloyee Employee#EmpName, DateHired, DateBirth, PayRate, JobTitle
Customer Customer#Custname, Address, AccountBalance, CreditLimit
SaleOrder-InventorySaleOrder#, Product#
Sale-InventoryInvoice#, Product#
Sale-CashReceipt Invoice#, RA#
Use foreign keys to implement one-to-one and one-to-many relationships
Foreign key (field property required or not required) If minimum cardinality for foreign key posting is
1(mandatory), field property attribute should be set to required
The six circled foreign key attributes field property should be set to required in the database table to avoid possibility of null value
SALES
CASH RECEIPT
EMPLOYEESALES REP
CUSTOMER
EMPLOYEECASHIER
INVENTORY
CASH
Duality
Partic-ipation 3
Partic-ipation 4
Partic-ipation 5
Partic-ipation 6
Stockflow 1
Stockflow 2
Fred's Train Shop Revenue Cycle
(0,N)
(0,N) (0,N)
(0,N)
(0,N)
(0,N)
(1,1)
(1,1)
(0,1)
(0,N)
(0,N)
(1,1) (1,1)
(1,N)
Sale Order CUSTOMERPartic-ipation 1
Partic-ipation 2
(0,N)
(0,N)
(0,N)
(1,N)
(1,1)
(1,1)
(0,1)
(0,1)
C-Acct# C-BalType RA# TimeDate Pmt method
Emp# DOBDateHired
Pay Rate
Job Title
Cust# Cname CreditLimit
EmpName
Address
AcctBalanceDateSO# Time Comments
Date
Inv#
Time InvSent(Y/N)
Prod# DescList-Price
Std-cost
QOH QAvai
Reorder-Qty
Reorder-Pt
Qty Ordered
Qty Sold
Actual SalePrice
Amopunt Applied to
Invoice
25
Foreign keys in bold red should have property attribute set to required to avoid null value.
AttributesTables Primary key Foreign Key(s) Other Attributes
SaleOrder SaleOrder#Customer#, Employee#
Date, Time, Comments
Sale Invoice#SaleOrder#, Customer#, Employee#
Date, Time, InvoiceSent(Y/N)
CashReceipt RA#Customer#, Employee#, Account#
Date, Time, PmtMethod
Inventory Product#Desc, ListPrice, StdCost, QtyonHand, QtyAvailable, ReorderQty, ReorderPoint
Cash Account # BegBalance, AcctType
Emoloyee Employee#EmpName, DateHired, DateBirth, PayRate, JobTitle
Customer Customer#Custname, Address, AccountBalance, CreditLimit
SaleOrder-InventorySaleOrder#, Product#
Sale-InventoryInvoice#, Product#
Sale-CashReceipt Invoice#, RA#
26
Cardinalities indicate that Customer participation in relationship is mandatory.
Since it is mandatory, to avoid possible null value, make this attribute required in the sales table
Foreign key (required or not required)
There are 4 relationship attributes. If relationship becomes a separate table, then relationship
attributes are placed in that table If relationship established via foreign key, attribute placed in
table with foreign key
SALES
CASH RECEIPT
EMPLOYEESALES REP
CUSTOMER
EMPLOYEECASHIER
INVENTORY
CASH
Duality
Partic-ipation 3
Partic-ipation 4
Partic-ipation 5
Partic-ipation 6
Stockflow 1
Stockflow 2
Fred's Train Shop Revenue Cycle
(0,N)
(0,N) (0,N)
(0,N)
(0,N)
(0,N)
(1,1)
(1,1)
(0,1)
(0,N)
(0,N)
(1,1) (1,1)
(1,N)
Sale Order CUSTOMERPartic-ipation 1
Partic-ipation 2
(0,N)
(0,N)
(0,N)
(1,N)
(1,1)
(1,1)
(0,1)
(0,1)
C-Acct# C-BalType RA# TimeDate Pmt method
Emp# DOBDateHired
Pay Rate
Job Title
Cust# Cname CreditLimit
EmpName
Address
AcctBalanceDateSO# Time Comments
Date
Inv#
Time InvSent(Y/N)
Prod# DescList-Price
Std-cost
QOH QAvai
Reorder-Qty
Reorder-Pt
Qty Ordered
Qty Sold
Actual SalePrice
Amopunt Applied to
Invoice
AttributesTables Primary key Foreign Key(s) Other Attributes
SaleOrder SaleOrder#Customer#, Employee#
Date, Time, Comments
Sale Invoice#SaleOrder#, Customer#, Employee#
Date, Time, InvoiceSent(Y/N)
CashReceipt RA#Customer#, Employee#, Account#
Date, Time, PmtMethod
Inventory Product#Desc, ListPrice, StdCost, QtyonHand, QtyAvailable, ReorderQty, ReorderPoint
Cash Account # BegBalance, AcctType
Emoloyee Employee#EmpName, DateHired, DateBirth, PayRate, JobTitle
Customer Customer#Custname, Address, AccountBalance, CreditLimit
SaleOrder-InventorySaleOrder#, Product#
QtyOrdered
Sale-InventoryInvoice#, Product#
QtySold, ActualSalePrice
Sale-CashReceipt Invoice#, RA# AmountAppliedtoInvoice 18-28
Relationship attributes
18-29
Retrieving Information from REA Database
Journals Information contained in event tables
Ledgers Information contained in resource tables
Financial statements Information contained in resources and Information on imbalances
Accounts receivable Sales transactions for which customer payments have
not yet been received Accounts payable
Purchases from suppliers that have not yet been paid for
18-30