为什么SQL Server不支持无符号数据类型?

时间:2022-08-15 16:59:06

I am specifically thinking about unsigned int.

我特别想的是无符号int。

Here is a practical example: what do you do when your identity column maxes out? It's possible to either go BigInt (8 bytes storage instead of 4) or to refactor the application to support negative integers, and even to create your own rules as indicated in this answer; neither of those options are optimal.

这里有一个实际的例子:当你的身份栏出现时,你会怎么做?可以使用BigInt(8字节存储而不是4字节存储)或重构应用程序以支持负整数,甚至可以创建您自己的规则,如本文所示;这两种选择都不是最佳选择。

UInt would be an ideal solution, but SQL Server does not offer it (where MySQL does).

UInt是一个理想的解决方案,但是SQL Server并没有提供它(MySQL在此提供)。

I understand that unsigned datatypes are not part of the SQL standard (SQL-2003) but still seems like a waste to me.

我知道没有签名的数据类型不是SQL标准的一部分(SQL-2003),但对我来说仍然是一种浪费。

What is the reason of not including these (in SQL Server or in the standard)?

为什么不包括这些(在SQL Server中或在标准中)?

3 个解决方案

#1


39  

If I had to guess, I would say that they are trying to avoid a proliferation of types. Generally speaking there isn't anything that an unsigned integer can do that a signed integer can't do. As for the case when you need a number between 2147483648 and 4294967296 you probably should go to an 8 byte integer since the number will also eventually exceed 4294967296.

如果我不得不猜测的话,我想说他们是在试图避免类型的扩散。一般来说,无符号整型没有无符号整型所能做的任何事情。对于这种情况,当您需要一个介于2147483648和4294967296之间的数字时,您可能应该使用一个8字节的整数,因为这个数字最终也会超过4294967296。

#2


39  

For that purpose you could use -2,147,483,648 as the seed value.

为此,你可以用-2,147,483,648作为种子值。

Identity(-2147483648, 1)

#3


30  

I found a similar question on Microsoft Connect.

我在microsoftconnect上发现了一个类似的问题。

The reply from Jim Hogg (Program Manager) has some pro's and con's for adding unsigned int's. The major con is the rules to implement implicit type conversions become a nightmare to get right.

Jim Hogg(程序经理)的回复中有一些关于添加无符号int的正反两面。主要的缺点是实现隐式类型转换的规则变成了纠正错误的噩梦。

The request was closed as "Won't Fix".

请求被关闭为“不会修复”。

#1


39  

If I had to guess, I would say that they are trying to avoid a proliferation of types. Generally speaking there isn't anything that an unsigned integer can do that a signed integer can't do. As for the case when you need a number between 2147483648 and 4294967296 you probably should go to an 8 byte integer since the number will also eventually exceed 4294967296.

如果我不得不猜测的话,我想说他们是在试图避免类型的扩散。一般来说,无符号整型没有无符号整型所能做的任何事情。对于这种情况,当您需要一个介于2147483648和4294967296之间的数字时,您可能应该使用一个8字节的整数,因为这个数字最终也会超过4294967296。

#2


39  

For that purpose you could use -2,147,483,648 as the seed value.

为此,你可以用-2,147,483,648作为种子值。

Identity(-2147483648, 1)

#3


30  

I found a similar question on Microsoft Connect.

我在microsoftconnect上发现了一个类似的问题。

The reply from Jim Hogg (Program Manager) has some pro's and con's for adding unsigned int's. The major con is the rules to implement implicit type conversions become a nightmare to get right.

Jim Hogg(程序经理)的回复中有一些关于添加无符号int的正反两面。主要的缺点是实现隐式类型转换的规则变成了纠正错误的噩梦。

The request was closed as "Won't Fix".

请求被关闭为“不会修复”。