Currency modeling in the database

A very naive question. I need to save the currency in the database. Both value and code. To solve this problem, people usually make 2 columns, one stores the value and the other code? Or is there a built-in type that I can use?

-Thanks

+5
source share
4 answers

You will need to use two columns. I would save the cash amount in one column and the alpha-currency code in another column. In some cases, you will have several amounts in one line. for example, the delivery amount and tax amount may be indicated on the invoice record. You will need to decide whether they will have the same currency or if you need two columns.

ISO.

+7

Money, . , ( , ..), .

: PostgreSQL , , , - .

+1

, (Oracle, Postgres, MySQL), , , - . .

0
source

Perhaps there are tools specific to your db. In general, I would think that storing currency as a real value and indicator of a currency code. There may be a standardized list of currency codes somewhere that you can use, or you can simply create it based on currencies that, as you know, will deal with.

Indeed, if you want to specify a type of any type, you will need a column to store the type.

People can provide additional help for specific databases if you indicate the database you are using.

0
source

All Articles