sql server 4 byte unsigned int(sql server 4 字节无符号整数)
问题描述
有谁知道我可以通过使用 4 个字节而不是使用 8 个字节和 bigint 来保存无符号整数(0 到 4294967295)的任何解决方法吗?
Does anyone know of any work around by which i can save unsigned integers (0 to 4294967295) simply using 4 bytes instead of using 8 bytes and bigint?
我知道我们可以创建用户定义的数据类型并对它们创建一个约束以不允许负值,但这仍然不允许我输入超过 2147483647 的值.我只想使用 4 个字节,但能够保存更大的整数值大于 2147483647 但小于 4294967295.
I know we can create user defined datatypes and create a constraint on them to not allow negative values but that still does not allow me to enter values over 2147483647. I only want to use 4 bytes but be able to save integer values greater than 2147483647 but less than 4294967295.
可能的重复:SQL Server 中的 4 字节无符号整数?
推荐答案
没有可用的无符号类型,因此您可以使用 UDT 创建一个,或者选择更大的数据类型.如果您在 UDT 中执行此操作,您将再次超过 4 个字节.
There is no unsigned type available to you, so you could create one using the UDT, or opt for the larger data type. If you do it in a UDT you are going to exceed the 4 bytes again.
最极端的做法是在您读取存储值后通过添加 -2^31 自动将偏移量应用于它,但这是一种真正的 hacky 方法,并且会使查看代码等的任何人感到困惑,而不是提及错误/遗漏的可能性.我根本不推荐 hack.
The extreme hack would be to apply an offset automatically to your stored value after you read it, by adding -2^31 but this is a real hacky way to go about it and confusing for anyone viewing the code etc, not to mention the potential for mistakes / things being missed. I wouldn't recommend the hack at all.
这篇关于sql server 4 字节无符号整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:sql server 4 字节无符号整数
基础教程推荐
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- 是否可以执行按位分组功能? 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- 在 SQL 中连接多个表 2021-01-01
- 无法解决整理冲突 2021-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
