planetp
planetp

Reputation: 16113

Database schema question

I have a table in a mysql database which contains exchange rates. Currently it is defined like this:

date | currency | rate

These rates use some base currency. Now I need to also store rates for another base currency. Is it better to create a separate table or use one table? What are the pros and cons of each method?

Upvotes: 1

Views: 721

Answers (2)

Neville Kuyt
Neville Kuyt

Reputation: 29649

Are you sure you need to store this with two base currencies? If you know the rate from dollars to euros, and euros to pounds, you can derive dollars to pounds.

If you do have to store both base rates, i_forget's answer is clearly right - you want your currency conversion code to be identical, not have to substitute table names depending on which currency you're using - if you have to go to 2 currencies, you have to consider the possibility you have to go to 200 currencies.

Upvotes: 2

plague
plague

Reputation: 1908

you can add a new column currency_from which is the start currency and change currency to currency_to which would be the currency being changed to

Upvotes: 2

Related Questions