Jump to content
Sign in to follow this  
El_Pablo

The price of a product in time

Recommended Posts

Hi,

How would you model the structure of the tables to know what was the price of a product in time? In a billing system it's important to keep the price up to date and also keep the price paid for a product for a specific time.

This is one of my approach

products (pkProductID, price (lookup from prices), ...)

prices (pkPriceID, fkProductIDprice, date, ...)

billDetail (fkProductID, fkBillID, price (lookup from product), ...)

Thanx for any other suggestion.

Share this post


Link to post
Share on other sites

The price in Products is redundant. The line item (billDetail) can lookup directly from Prices, based on ProductID and either the date or just the most recent price (depending on whether you have future prices and/or bill retroactively).

Share this post


Link to post
Share on other sites

To get the most recent price, I will need to create a script? I'm I right or there's another way?

Share this post


Link to post
Share on other sites

No, not at all - just sort the relationship by date (or by PriceID), descending.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

By using this site, you agree to our Terms of Use.