我已经被开发人员询问有关舍入问题的问题。
我们计划将数据库迁移到SQL Server 2016,在新的SQL平台测试期间,我们发现SQL Server 2016的四舍五入比预期的要少。
这种差异似乎是更改/设置更高兼容性级别时默认舍入方法更改的结果。
- 兼容模式130的SQL Server 2016数据库
declare @a float = -0.0051175 -- 7 digits
declare @b float = 0.0051175
select round(@a, 6), round(@b, 6)
Result
------------------------------------
-0.005117 , 0.005117
- 兼容模式为100的SQL Server 2016数据库
declare @a float = -0.0051175 -- 7 digits
declare @b float = 0.0051175
select round(@a, 6), round(@b, 6)
Result
-----------------------------------
-0.005118 , 0.005118
有没有人对此有任何想法?
答案 0 :(得分:0)
升级到SQL Server 2016 RTM CU3 / SP1并升级到数据库兼容性级别130时,还应执行其他DBCC检查。
这些隐藏在跟踪标志139后面,这应该暂时启用,作为将数据库兼容性级别更改为130的过程的一部分。
Enable trace flag 139 by running DBCC TRACEON(139, -1).
Run DBCC CHECKDB/TABLE..WITH EXTENDED_LOGICAL_CHECKS to validate persisted structures
Run DBCC CHECKCONSTRAINTS commands (if rows are affected the associated where clause to identify the row will be returned).
Disable trace flag 139 by running DBCC TRACEOFF(139, -1)
Change the database compatibility level to 130.
REBUILD any structures that you identified in step 1.
数据库级别130中存在表达式评估的影响,这会影响持久化结构
Check constraints
Persisted Computed columns
Indexes using computing columns whether as part of the key or as included columns
Filtered indexes
Indexed views
在尝试修复问题之前升级到兼容性级别130,以便将新的表达式评估逻辑用于修复。
Check constraints – change data or drop/recreate constraint with new expression
Persisted Computed columns – Update a column referenced by the computed column to the same value to force recalcuation of the computed column
Index/filtered index/indexed views – Either A) Put db in single user mode and run DBCC CHECKTABLE with REPAIR_REBUILD B) ALTER INDEX…REBUILD and if supported in your edition of sql server consider adding the WITH (ONLINE=ON) clause.
注意:上述文章的附录C / D中有一些查询可用于帮助识别受影响的对象。"