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 字节无符号整数


基础教程推荐
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
- 带更新的 sqlite CTE 2022-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01