I need to enter a value which can be either decimal or int. What is the data type I need to set for the column in the database?
1 Answer
considering you have two different value types it may be more beneficial to have to NULLable columns with different data type. If you have like 100-1000 rows in a table it's not an issue and you can go with big DECIMAL(18,3) or even DECIMAL(38,10) as needed and convert everything to this big format.
However if you hit billions of rows you should keep in mind that while standard INT is only 4 bytes big, the smallest DECIMAL is 5 bytes and that's for precision under 10. For wider values it can easily grow into 9 bytes or more, more than doubling storage space used.
Decimal(3,2)means three digits all in all, two of which being after the decimal separator. So you can only enter one digit before the comma. Usually you'd use something likeDECIMAL(18,3)or so.