Solved

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

Posted on 2009-05-18
4
922 Views
Last Modified: 2012-08-14
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
Comment
Question by:robfendergibson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 15

Accepted Solution

by:
mohan_sekar earned 125 total points
ID: 24415240
DBCC CHECKIDENT (tblName, RESEED, 0)
0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 24415365
another option is to TRUNCATE the table instead of clearing the data and the resetting the identity seed

truncate table
0
 
LVL 39

Expert Comment

by:BrandonGalderisi
ID: 24415371
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
 

Author Closing Comment

by:robfendergibson
ID: 31582726
Thanks Mohan, going with yout solution as the first one nad worked fine.  Also thanks to other contributers.

best wishes, Rob
0

Featured Post

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question