|
|
Question : Sales ER Diagram
|
|
I need to know some ideas for a sales recording ERD. I will supply you with basic information of existing tables and supply the ideas I have developed. I have yet to find an idea that I like, or approve of.
(ignore shipping) Customer table with generic fields Product table with a prod_id and basic product info Invoices table with (this is where i need help) what fields? Order table with seperate record for each item ordered
Do I link the invoices table to the product and customer table? Do I replicate all payment information ect thats in the customer table and all the product information that the customer bought in the invoices table?
One method I figured to do was to duplicate the customer and product table for the invoices table. And have the invoices table link to that table. Everytime a purchase is made, it looks for that customer in the duplicated table, if he's found then it links the invoice table to the duplicated customer table record, or creates a new record for that customer. This will also proceed to do the same method with the duplicated product table.
Heres an example.. (long example sorry)
Customer table id: 1000 name: Brad phone: 555
Product table id: 200 name: book price: 12 desc: many pages
Invoices table inv_id: 1 date: 12/31/05 amount: 24 cust_id: 1
Orders table inv_id: 1 prod_id: 1 qty: 2
Duplicated Customer Table cust_id: 1 orig_id: 1000 Name: Brad phone: 555
Duplicated Product Table prod_id: 1 orig_id: 200 name: book price: 12 desc: many pages
*******Then the price of product 200 is changed from 12 to 5 and a new purchase is made******* Customer table id: 1000 name: Brad phone: 555
Product table id: 200 name: book price: 5 desc: many pages
Invoices table inv_id: 1 date: 12/31/05 amount: 24 cust_id: 1 ----------------- inv_id: 2 date: 1/1/06 amount: 10 cust_id: 1
Orders table inv_id: 1 prod_id: 1 qty: 2 ---------------- inv_id: 2 prod_id: 2 qty: 2
Duplicated Customer Table cust_id: 1 orig_id: 1000 Name: Brad phone: 555
Duplicated Product Table prod_id: 1 orig_id: 200 name: book price: 12 desc: many pages ----------------------------- prod_id: 2 orig_id: 200 name: book price: 5 desc: many pages
*******Then the customer 1000 changes billing name to Joe and buys******* Customer table id: 1000 name: Joe phone: 555
Product table id: 200 name: book price: 5 desc: many pages
Invoices table inv_id: 1 date: 12/31/05 amount: 24 cust_id: 1 ----------------- inv_id: 2 date: 1/1/06 amount: 10 cust_id: 1 ----------------- inv_id: 3 date: 1/2/06 amount: 15 cust_id: 2
Orders table inv_id: 1 prod_id: 1 qty: 2 ---------------- inv_id: 2 prod_id: 2 qty: 2 ---------------- inv_id: 3 prod_id: 2 qty: 3
Duplicated Customer Table cust_id: 1 orig_id: 1000 Name: Brad phone: 555 ---------------------------- cust_id: 2 orig_id: 1000 Name: Joe phone: 555
Duplicated Product Table prod_id: 1 orig_id: 200 name: book price: 12 desc: many pages ----------------------------- prod_id: 2 orig_id: 200 name: book price: 5 desc: many pages
**************DONE*************
The order of events...
1) Customer purchases 2) Duplicated Customers table is searched for orig_id and checks fields for changes a) Record is inserted if changes made b) Else use the matched ID 3) Duplicated Products table is searched for orig_id(s) and checks fields for changes a) Record(s) is inserted if changes made b) Else use the matched ID(s) 4) Invoice record created with found or newly entered customer ID 5) Orders records created with found or newly entered product ID(s)
Well that's the best sufficient solution I can come up with to avoid customers/products being deleted/modified and not losing any information. The other method is to straight up copy the data into the invoice/orders record without linking to external duplicate tables. That will possibly create enourmous more amounts of data. My solution saves disk space proportionate to the number of sales made to unchanged data. 5000 different customer sales on one product only uses 1 product record until changed. Worse case scenario is 1000 customers purchase the same product on different occasions 5 times, each time the product changed, and the customer information changed each time. Which would be a total of 4000 extra customer records and 4 extra product records.
To further save space you could split the customer information into portions and have the tables linking to each other (very messy and not 3N). This would almost eliminate unneccesary duplications. Data that is expected to change frequently such as credit card information could be stored in their own tables. While information such as zip code contact phone number, email ect is stored in its own table, and shipping information stored in its own table.
So a Billing information, shipping information, and generic information tables split that are still being duplicated with the method above, but are all linked through the invoices record.. not linked to each other in any way.
/-- Shipping Information Record # Invoices---- Generic Information Record # 1 \-- Billing Information Record # | | X Orders ---- Product ID (duplicated table)
I am thinking about this as I go and that solution I just proposed sounds the most logical.. hmm.. I almost like that idea.. god this is driving me NUTS.
I can't come up with a solution that I enjoy, and don't know where I can go to for solutions, like classes or books ect. I will be posting back with maybe updates.. been struggling with this for a few days.
|
Answer : Sales ER Diagram
|
|
Yes.. that is what I am saying if you look at my table.
Day 1 Product Price $12
A sales is made.
Prod Table ID 1 ProdName abc Description xxxxxx Price 12
Invoice Table ID 1 CUstID 10 Amount 12
Order Table ID 1 InvID 1 ProdID 1 Qty 1 Amount 12
We have captured the price on Order Table and it is valid at that point of time, on Day 2 you can change the price on Product Table to $14 and all day2 sales will capture as $14..
The above relational model had been adopted by many of my clients for years and we dun have any problem with it.
|
|
|
|
|