Reset PK auto increment column

2019-05-16 06:07发布

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条回答
在下西门庆
2楼-- · 2019-05-16 06:16

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

查看更多
登录 后发表回答