SQL 数据类型负十进制
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8041917/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SQL DataType Negative Decimal
提问by user979331
Im inserting Data into a database, they have a decimal and a negative number, is there a way to the DataType Decimal into negative numbers or is there another data type I can use?
我将数据插入数据库,它们有一个小数和一个负数,有没有办法将 DataType Decimal 转换为负数,或者我可以使用另一种数据类型吗?
回答by
The decimal
datatype can store negative numbers as well. So to answer your question, yes you can use the decimal
datatype to store negative decimal numbers.
该decimal
数据类型可以存储负数为好。所以要回答你的问题,是的,你可以使用decimal
数据类型来存储负十进制数。
Here is some proof:
这里有一些证据:
create table NegativeDecimal
(
somedec decimal(10, 4) not null
)
go
insert into negativedecimal
select -12.3
union all
select 16.4
go
select *
from NegativeDecimal
somedec
---------------------------------------
-12.3000
16.4000
(2 row(s) affected)
EDIT: This is provided you are using SQL Server. Please specify your RDBMS.
编辑:这是提供您使用 SQL Server。请指定您的 RDBMS。
回答by Marc B
You don't state which DBMS you're using, but on MySQL at least, negatives are supported in decimals:
您没有说明您使用的是哪个 DBMS,但至少在 MySQL 上,负数支持小数:
mysql> create table x (x decimal(5,2));
Query OK, 0 rows affected (0.06 sec)
mysql> insert into x (x) values (-3.14);
Query OK, 1 row affected (0.00 sec)
mysql> select * from x;
+-------+
| x |
+-------+
| -3.14 |
+-------+
1 row in set (0.00 sec)
回答by elopez
For math definition decimal number could be positive or negative and the data structures know that, for the same reason is not a special type for negative or positive numbers
对于数学定义,十进制数可以是正数或负数,并且数据结构知道,出于同样的原因,十进制数不是负数或正数的特殊类型