Inception

A world beyond boundaries, my world

How to reset Identity Seed Column in SQL Server

with one comment

It could’nt have got more difficult then this….. :)

Just got stuck with this very painful and mind blasting task. Well it may sound so stupid but sometimes the easisets of the things are ones you cannot answer. this evening I was working on a client database and after having deleted all the information from a table we wanted to repopulate it with a new set of data. The primary key was the all famous Identity seed. So that means inspite of deleting all the data it would start assiging the primary key number from where it had last stopped and not from 1 again.

So if you want to restart from 1, there are 2 approcahes to this:-

1. Instead of deleting table use truncate table which will delete all data and also reset the primary key.

2. but if you have already deleted the data then you can just use the DBCC CHECKIDENT(‘Customer’, RESEED, 0) command where Customer is table name.

Have a nice day :-|

Written by Zaheed

July 22, 2010 at 5:11 am

One Response

Subscribe to comments with RSS.

  1. Nice post! ;-)

    Flying Tech

    CTEric

    July 23, 2010 at 3:08 pm


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.