数据库自增列增大1000的原因及解决方法

来源:互联网 发布:淘宝u站首页在哪里 编辑:程序博客网 时间:2024/05/17 09:35

在使用SQL Server 2012数据库设置自增列时,有时候自增列值突然增大1000,比如这样


不要慌!这是SQL Server 2012故意这么设计的。

原因:

来看看SQL Server 2012的英文介绍

From SQL Server 2012 version, when SQL Server instance is restarted, then table's Identity value is jumped and the actual jumped value depends on identity column data type. If it is integer (int) data type, then jump value is 1000 and if big integer (bigint), then jump value is 10000. From our application point of view, this increment is not acceptable for all the business cases specially when the value shows to the client. This is the special case/issue ships with only SQL Server 2012 and older versions have no such issue.

蹩脚的翻译

从SQL Server2012版本中,当SQL Server重新启动时,则表的IDENTITY值跳起来,实际跳下值取决于标识列的数据类型。如果它是整数(INT)数据类型,则跳值为1000,如果是大的整数(BIGINT),则跳值为10000。从我们的应用程序的角度来看,这个增量在所有的商业案例中是无法接受的,特别是当值展示给客户端时。这是特殊情况,只有SQL Server 2012有这个问题,旧版本并没有这样的问题。

通俗的讲

这是由于重启数据库服务造成的,自增列突然增大1000是给数据同步预留用的。比如两台服务器做了数据同步,其中一台服务器要重启,而在这时另一台服务器又有新的数据插入,这1000行就是预留给这些新的数据的,以避免两台服务器的数据冲突。

解决方法:

1打开 计算机管理
2左边 选择SQL Server服务
3右边 右击SQL Server(MSSQLSERVER) 选择 属性
4选择 启动参数
5在参数里输入  -t272 依次点击 添加、应用、确定



***************************************************************************************************************************

2017年咯,还是本命年呢,希望新的一年,能学到更多技术,工作和生活一切都顺顺利利的,嘿嘿嘿!大笑



0 0