SunQuest
           Database Management
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesDatabase Management

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old September 2nd, 2003, 08:33 AM
kwehchap kwehchap is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 10 kwehchap User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
database design

need some guru advice on database design.

okay, say i have a database something like this

- customers
- sales
- salesLineItems
- products

so when the customers buy, a sale is created with several salesLineItems, each linked to a product. simple.

the problem comes when i need to change the details of the product, after the sale has been transacted. for example, i increase the price of a product by $1

in this case, my transaction history (the records in my sales and salesLineItem) will not be reflecting the correct information, because it is linked to the product... the sales reports calculated at the end of the month may not tally with the actual amount of money i collected from the transactions, becasue the records now reflect the new product price.

normally, what is done? do i make a copy of all the product information on each salesLineItem record?

Reply With Quote
  #2  
Old September 2nd, 2003, 10:47 AM
crimson117 crimson117 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: New York
Posts: 19 crimson117 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to crimson117 Send a message via AIM to crimson117 Send a message via Yahoo to crimson117
The problem you are describing is due to the fact that products can have multiple prices over time, but you've only allocated a single spot to store the price. You need to be able to store multiple prices, since one product can have many prices.

I'd keep "products" and "prices" in separate tables, with rows in the "prices" table pointing to a particular product. A product can have many prices, a price can have only one prodcut. The Prices table would have columns such as "StartDate", "EndDate", "Region", "Amount".

That way, you could have prices change as time goes by but not forget what the price used to be in the past. Each "sale" on the sale table would have a TransactionDate. You would match the transaction date and product and region to find what price the customer should be charged.

You could add other attributes to "prices" such as "couponCode" so if a person had a coupon for the particular product, they'd get a special price. The coupon would be recorded in the Sale table, or in a separate UsedCoupon table that points to the Sale table.

So bottom line is start thinking of Prices as being complex objects, and belonging to a product, rather than just being a simple attribute of a product.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesDatabase Management > database design


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway