S
S
Sergey delphinpro2021-04-15 14:34:48
Database design
Sergey delphinpro, 2021-04-15 14:34:48

What is the best way to organize the storage of exchange rates?

What is the best way to organize the storage of exchange rates so that there are no problems?
All world currencies are required. At the first stage, one base is USD, later quotes of random pairs will be needed. Update - once a day.
The first is the data format. Esteemed, advise to use decimal (20,6). It is right?

Second - table organization
I see two options.
1. One table

id | timestamp | source | и туева хуча столбиков под каждую валюту


2. Two tables with One-to-Many relationship

id | timestamp

relation_id | source | currency | value

The first one is simpler, the second one seems to be more flexible.
How do they generally do it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
DevMan, 2021-04-15
@delphinpro

if the Selections will "take a fresh (last, today's) USD to Tugrik quote" , why do you bother with the classic database at all?
received fresh quotes, put them in some kind of radish and use them. repeat every day.
if you need a story, then option 2.

C
cicatrix, 2021-04-15
@cicatrix

6 decimal places may not be enough, in theory, I would take 8 just in case.
To organize tables, you first need to understand how these tables will be used.
If there is a selection of the type "select quotes for all currencies on the date", then the date should be a key (or index), then like this:
DATE / tueva hucha of
columns be a currency code.
CURRENCY CODE / Date / Rate
TimeStamp is needed only if your value changes within one day. Usually the rates are set per day, so one date is enough.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question