views:

25

answers:

2

How do I reset the Primary Key index to 1 using Visual Studio 2008 Server Explorer?

Thanks!

+1  A: 

It sounds like you have a table, with data, and you want to restart PK Identity numbering back to 1.

You'll have to delete all data and reset the seed on the identity column. This can be done all in one statement.

Create a new query by right-clicking on the database server or a table, and choose New query (or whatever command is similar):

TRUNCATE TABLE MyTable;
p.campbell
Yes, that is what I want to do. Can I do it from the Server Explorer?
B Seven
@B Seven: yes, right click on the db or a table, and hit New Query (or similar)
p.campbell
It is quite right that TRUNCATE is the correct way to do this. You however have to make sure that no other table is referencing the table (using it as a part of it´s foreign key) then you cannot do truncate.
bjorsig
+1  A: 

To reset the IDENTITY value to one, use DBCC CHECKIDENT:

DBCC CHECKIDENT (‘YOUR_TABLE_NAME_HERE’, RESEED, 1)
OMG Ponies