abdelhedi hlel
abdelhedi hlel

Reputation: 3709

Why the identity specification gives false results SQL Server (asp net)

The identity specification starts from the last number +1 even I have deleted all rows, it never starts from 1.

The REsult

Upvotes: 1

Views: 72

Answers (3)

Alvimar
Alvimar

Reputation: 498

If you want to start the first number after deleting all items, you need to reset the seed.

https://technet.microsoft.com/en-us/library/ms176057.aspx

DBCC CHECKIDENT ('[Table]', RESEED, 0);
GO

Upvotes: 0

Sean Lange
Sean Lange

Reputation: 33581

When you delete rows from your table the identity value is not reset. You need to either truncate the table (which will reset the identity) or RESEED the identity.

https://msdn.microsoft.com/en-us/library/ms176057.aspx

Upvotes: 4

Xavier J
Xavier J

Reputation: 4634

The identity spec isn't designed to restart from 1 after you do DELETE operations on a table. You have to TRUNCATE TABLE to reset to 1.

Upvotes: 0

Related Questions