Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

storing negative value in mysql

How can I store negative value in mysql decimal? I have data from DMS to Decimal having negative values, so it is decimal and negative. So what can I use to store such value?

like image 332
Hafiz Avatar asked Dec 27 '11 11:12

Hafiz


People also ask

Can MySQL store negative number?

If UNSIGNED is used with DECIMAL , negative values are not allowed. MySQL stores numbers in DECIMAL columns as strings. Therefore, numbers outside the maximum numeric range for this data type may be stored in a DECIMAL column.

How do you store negative numbers in SQL?

Numeric value is positive. Numeric value is negative. Returns the ones complement of the number. The + (Positive) and - (Negative) operators can be used on any expression of any one of the data types of the numeric data type category.

Can SQL store negative values?

So to answer your question, yes you can use the decimal datatype to store negative decimal numbers.

Which datatype hold negative values?

Type P and Type I will hold a negative.


2 Answers

Use MySQL DECIMAL type?

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

like image 180
gbn Avatar answered Sep 22 '22 01:09

gbn


In case you want to store a negative integer - (INT) will work nicely, unless it's not UNSIGNED.

https://dev.mysql.com/doc/refman/8.0/en/integer-types.html

In case you want to store a negative decimal - (DECIMAL) is the way to go, as GBN mentioned above.

https://dev.mysql.com/doc/refman/5.7/en/precision-math-decimal-characteristics.html

like image 3
Rossitten Avatar answered Sep 25 '22 01:09

Rossitten