Reputation: 113
I have to save the the value -1
. Is for it more correct to use a data type of tinyint(1)
or tinyint(2)
and why?
I know that I can also store with tinyint tinyint (1) many more digits, but I want to know what you use in my case.
Upvotes: 4
Views: 14698
Reputation: 172628
You may use DECIMAL which would be probably the best datatype for storing negative numbers.
Standard SQL requires that DECIMAL(5,2) be able to store any value with five digits and two decimals, so values that can be stored in the salary column range from -999.99 to 999.99
Although in your case you may use TINYINT(1) as it takes 1 byte of storage and its range is -128 to 127.
On a side note:
You may also like to know what is the difference between TinyInt(1) and TinyInt(2)
M indicates the maximum display width for integer types. The maximum display width is 255. Display width is unrelated to the range of values a type can contain, as described in Section 11.2, “Numeric Types”. For floating-point and fixed-point types, M is the total number of digits that can be stored.
Upvotes: 2