Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Currency modeling in database

A very naive question. I need to store currency in the database. Both the value and the code. To solve this, do people generally make 2 columns, one storing the value and other the code? Or is there an inbuilt type I can use?

-thanks

like image 432
Mak Avatar asked Dec 04 '09 01:12

Mak


People also ask

What is database modeling with examples?

Data Models Describe Business Entities and Relationships Data models are made up of entities, which are the objects or concepts we want to track data about, and they become the tables in a database. Products, vendors, and customers are all examples of potential entities in a data model.

What is the currency of data?

Data currency is monetary value assigned to data to identify its financial significance to an organization. Once the monetary value of data assets is identified, it may be used as the unit of exchange in a transaction, either as the sole payment or in combination with money.


2 Answers

You will need to use two columns. I would store the monetary amount in one column and the alpha currency code in another column. In some cases, you will have multiple amounts on a single row. e.g. shipping amount and tax amount may both be on the invoice record. You will need to decide if these will share the same currency or if you need two columns.

You should use the ISO standard currency codes.

like image 151
WW. Avatar answered Sep 20 '22 03:09

WW.


Some databases have a Money type, which can be used to store the value. However, if you want to store a code (do you mean dollars, euro's etc?) then you would need to use a second column.

Update: PostgreSQL does have a money type, although it looks like it would only support one type of currency so it still does not really meet your needs.

like image 39
Justin Ethier Avatar answered Sep 21 '22 03:09

Justin Ethier