Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 933
  • Last Modified:

Reset table autonumber with Microsoft SQL Management Studio Express (SQL 2005)

Hi Experts,

Excuse my ignorance on this one.  I have an SQL 2005 database and using Studio Express to look at the data etc.  I have cleared all the data from the tables but cannot see how to reset the autonumbers in each table back to 1.  Is there a simple way of doing this?  With Access I use 'Compact and Repair' - is there something similar with Studio Express?

Many thanks, Rob
0
robfendergibson
Asked:
robfendergibson
1 Solution
 
mohan_sekarCommented:
DBCC CHECKIDENT (tblName, RESEED, 0)
0
 
Aneesh RetnakaranDatabase AdministratorCommented:
another option is to TRUNCATE the table instead of clearing the data and the resetting the identity seed

truncate table
0
 
BrandonGalderisiCommented:
or, if you issue a truncate table when deleting all records it will reset the identity value as well as deleting the data.  This however, will not work on tables referenced by foreign keys.
0
 
robfendergibsonAuthor Commented:
Thanks Mohan, going with yout solution as the first one nad worked fine.  Also thanks to other contributers.

best wishes, Rob
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now