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


- 导入具有可变标题的 Excel 文件 2021-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- SQL 临时表问题 2022-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- 更改自动增量起始编号? 2021-01-01