如何在gridview中删除行时设置自动增量?
问题描述:
DBCC CHECKIDENT('databasename.dbo.tablename',RESEED,number)
我试过这个但是我没有删除数据库中的行只显示它设置标志激活。当一行被删除时,它被设置为假标志,插入另一行后,它显示增加虚假标志+1的ID。
我们如何解决这个?
我的尝试:
DBCC CHECKIDENT(' databasename.dbo.tablename',RESEED,number)
DBCC CHECKIDENT('databasename.dbo.tablename', RESEED, number)
I have tried this but am not deleting the rows in database only displaying it by setting flag active.when a row is deleted it is set as false flag and after inserting another row it displays ID incrementing the false flag +1.
How can we solve this?
What I have tried:
DBCC CHECKIDENT('databasename.dbo.tablename', RESEED, number)
答
如果您计划减少SEED的标识列,则不能在不删除行的情况下执行此操作。例如你有5行,你不能将种子设置为5而不删除第5行。
这里有两种摆脱这种方式的方法
1.不要在申请表中显示标识栏。
2.从此表中删除并保存其他历史记录表
希望这个帮助。
If you are planning to decrement SEED for identity column, you cannot do it without without deleting rows. example you have 5 rows, you can not set seed to 5 without deleting 5th row.
Here are two ways to get rid of this
1. Do not display identity column in application.
2. Delete it from this table and save it other history table
Hope this helps.
如果您认为需要这样做,那么您的数据库存在严重的设计问题。你永远不应该这样做。
If you think you need to do this you've got a serious design problem with your database. You should NEVER have to do this, ever.