sql服务器身份规范不连续 [英] sql server identity specification not sequential

查看:126
本文介绍了sql服务器身份规范不连续的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到SQL Sever(2008 express)在插入自动递增身份规范时随机跳转。



例如,我的一个列HitStat_ID将顺序插入15,16,17,18,然后突然,它会决定跳转,说1012 ,1013,1014 .... then 9120,9121等。



这不重要,只要它们是唯一的这个?它在一个以上的表也做了...
奇怪的是,这只是在最后一周左右,但应用程序已经开发了几个月!



ETA:在ASP.NET中工作VB
这是插入(在这种情况下):

  sql =INSERT INTO [HitStats]([PageName],[Date_and_Time],[User_ID])values('Home',
'+ TheDateTime +',' )+')
Dim dbcmd As SqlCommand = New SqlCommand(sql,dbconn)
dbcmd.ExecuteNonQuery()
dbcmd.Dispose()



请不要关于sql注入blah blah,它不会发生!

解决方案

如果您使用应用程序和事务,当您回滚事务时,您将丢失生成的自动递增数字。



查看更多此处



此外,如果删除数据,再次获得生成的数字,除非你做种子。
请参见此处


I have noticed that SQL Sever (2008 express) is randomly jumping forwards when it is inserting auto-incrementing identity specifications.

For example one of my columns "HitStat_ID" will insert sequentially 15, 16, 17, 18, then all of a sudden, it will decide to jump to, say 1012, 1013, 1014.... then 9120, 9121 etc.

It doesnt matter really, so long as they are unique (which they are) but why would it do this? its doing it in more than one table too... The odd thing is that is only done this over the last week or so, but the application has been in development for months!

ETA: Im working in ASP.NET VB This is the insert (in this case):

sql = "INSERT INTO [HitStats] ([PageName], [Date_and_Time], [User_ID]) values ('Home',     
'" + TheDateTime + "', '" + Session("User_ID") + "')"
Dim dbcmd As SqlCommand = New SqlCommand(sql, dbconn)
dbcmd.ExecuteNonQuery()
dbcmd.Dispose()

please dont go on about sql injection blah blah, its not going to happen!

解决方案

If you're using an application and transactions, when you rollback a transaction you will loose that Auto-incrementing number generated. Also if you make some inserts and rollback them.

See more here

Also, if you delete data, you won't get again that numbers generated, unless you do a reseed. See here

这篇关于sql服务器身份规范不连续的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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