What is the best type in SQL to use with CryptoCurrency?

8

I am developing a system where I will store transactions of CryptoCurrencies, type Bitcoin, I can not in any way have problems of conversion and rounding, in C # I checked and the best is decimal , right?

The values will be in this format:

  

0.000001

I know that money in SQL Server is not a good option, should I go for a decimal (x,x) ?

I can use SQL Server or MySQL database, so I put the tag of the two here, as it is still being decided

    
asked by anonymous 08.12.2017 / 19:31

1 answer

3

To store monetary values, you should avoid the data type float ( floating point ) . This applies to any language. As for data type money , it works correctly, with 4 fixed decimal places.

For example, you need 6 decimal places, which eliminates the use of money data type. In SQL Server you can use decimal

, s ), where p is precision and s is the scale . That is, use 6 as a scale. To define precision, note that you need to account for both the whole part and the fractional part. For example, to store values up to 9,999,999,999 are 4 figures in the whole part and 6 figures in the fractional part. Therefore, the precision must be% 4 + 6 = 10
That is, decimal (10, 6) .

As for MySQL, I have not used it for some time, except for sporadic testing. But, referring to the documentation, it's the same SQL Server rule as defining precision and scaling.

Documentation:

Read also:

09.12.2017 / 12:12