0

After I delete all values in table in sql and add new set of values, the id for new values keep showing cumulative of the deleted values. How do I start from 0 id and not cumulative of the deleted values? Please help.

Sonam
  • 87
  • 2
  • 9
  • You could do something like: http://stackoverflow.com/questions/8923114/how-to-reset-auto-increment-in-mysql – jhhayashi Mar 23 '17 at 07:23
  • Using MS SQL you can use the TRUNCATE statement the delete the whole table and let the identity start back from 1. – Kevin Mar 23 '17 at 07:24
  • @Kevin how do i do that without deleting the whole table? thanks. – Sonam Mar 23 '17 at 07:27
  • 1
    @Sonam what you're suggesting actually sounds like bad practice. I wouldn't recommend doing that. – Bugs Mar 23 '17 at 07:32

2 Answers2

0

Depends on the database you are using.

For mysql for instance you could use:

ALTER TABLE tablename AUTO_INCREMENT = 1

to reset the counter

ramden
  • 798
  • 1
  • 9
  • 25
0

To reseed the identity without using TRUNCATE you can use

DBCC CHECKIDENT ('<YourTable>', RESEED, 0);
GO

First execute the DELETE statement and then run the DBCC command.

For more info: Mircosoft MSDN DBCC CHECKINDENT

Kevin
  • 751
  • 6
  • 12