为什么 SQL Server 不支持无符号数据类型? [英] Why doesn't SQL Server support unsigned datatype?

查看:35
本文介绍了为什么 SQL Server 不支持无符号数据类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我特别考虑无符号int.

这是一个实际示例:当您的标识列用完时,您会怎么做?可以使用 BigInt(8 字节存储而不是 4 字节存储)或重构应用程序以支持负整数,甚至可以创建自己的规则,如 这个答案;这些选项都不是最佳选择.

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.

UInt 将是一个理想的解决方案,但 SQL Server 不提供它(MySQL 提供).

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

我知道无符号数据类型不是 SQL 标准 (SQL-2003) 的一部分,但对我来说仍然是一种浪费.

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

不包括这些(在 SQL Server 或标准中)的原因是什么?

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

推荐答案

如果让我猜的话,我会说他们正在努力避免类型的激增.一般来说,没有什么是无符号整数可以做的有符号整数不能做的.至于您需要 2147483648 和 4294967296 之间的数字的情况,您可能应该使用 8 字节整数,因为该数字最终也会超过 4294967296.

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.

这篇关于为什么 SQL Server 不支持无符号数据类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆