为什么SQL服务器主键跳过编号 [英] Why SQL server primary key skip number

查看:88
本文介绍了为什么SQL服务器主键跳过编号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Sql Server 2012并且我创建了一个表并将id保持为主键也标识规范是用于自动增量1.

但问题是表跳过数

例如1,2,3,4,5,6,7,8,9,10,11,12

和一些时间这个跳过数字和给出是101,102,103等等在

为什么



我尝试过的事情:



我正在使用Visual Studio 2013开发的网站

I am using Sql Server 2012 and i create a table and kept id as primary key also identity Specification "Yes" for auto increment 1.
but problem is this that table skip number
for example 1,2,3,4,5,6,7,8,9,10,11,12
and some time this skip number and give is 101,102,103 and so on
why

What I have tried:

I am using Visual Studio 2013 for developed website

推荐答案

请参阅StackOverflow上的讨论:身份增量在SQL Server数据库中跳跃 - Stack Overflow [ ^ ]

和:为什么我的自动递增Id在SQL Server中跳过数字? - 堆栈溢出 [ ^ ]
See this discussion on StackOverflow: Identity increment is jumping in SQL Server database - Stack Overflow[^]
and: Why does my auto-incremented Id skip numbers in SQL Server? - Stack Overflow[^]


这背后可能有几个原因,最常见的是删除记录并回滚事务。



但更大的问题是,为什么这对你来说是一个问题?自动递增字段的唯一想法是它为单个记录提供唯一值。就这样。它并不保证所有价值都存在等等,只是唯一性。



这种类型的密钥通常不会向用户显示,因为除了提供密钥值之外没有其他意义。换句话说,它是代理 [ ^ ]
There can be several reasons behind this, most typical ones are deletion of records nad rolling back a transaction.

But the bigger question is, why this is a problem for you? The sole idea of the auto incremented field is that it provides you a unique value for a single record. That's all. It does not quarantee that all values are present and so on, just the uniqueness.

This type of key is typically never shown to the user because it has no other meaning than providing a key value. In other words it's a surrogate[^]


这篇关于为什么SQL服务器主键跳过编号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆