Reset PK auto increment column

佐手、 提交于 2019-12-22 10:34:54

问题


I've been importing thousands of records multiple times in an effort to get the import running perfectly.

As a result, now when I do the live import before release, the ID columns for the auto increment column are on around 300,000.

Is there any easy way to 'reset' this once I have deleted all the data from these tables? I only want to for SEO reasons, the URL:

Forum/1/Post
Forum/35/Post
Forum/5600/Post

Looks a lot nicer and more concise (therefore more clickable in results) than

Forum/300124/Post
Forum/370321/Post
Forum/450111/Post

I'd rather not delete the column and reinsert the column as it would ruin all relationships and mean I'd have to refresh all my data context diagrams etc.


回答1:


You'll need the DBCC CHECKIDENT command with the reseed option, not sure I buy that it will improve SEO though.

DBCC CHECKIDENT ("dbo.Table", RESEED, 0); --next id will be 1

http://msdn.microsoft.com/en-us/library/ms176057.aspx



来源:https://stackoverflow.com/questions/5593623/reset-pk-auto-increment-column

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!