1

When I Delete data from a column that has identity seed id turned on, it doesnt reset back to the proper number but continues to count. For example:

I add ten items , so the latest added item will have id of 10, when i delete the items from database, the Id should reset itself back to 0 for example, but it still counts up starting from 11.. it not trully consistent, I'm using Entity Framework to add/delete stuff from database, so my question is, is there anyway to fix this? maybe through the Entity requests/queries?

1
  • 1
    If you're deleting everything in the table and want the identity to reset as well, just use TRUNCATE. Commented Nov 12, 2011 at 18:44

2 Answers 2

3

This is the proper behavior of an identity column. The value will continue to increment. If you add 11 items, starting at 1, the next would be 12. If you delete the first 10, you would not want the identity value to start back at one, because you will have a conflict at the 11th value. If you would like to reseed the table, you can use DBCC CHECKIDENT

Truncating a table will also reset it's identity value.

Sign up to request clarification or add additional context in comments.

Comments

0

cmd.CommandText = string.Format("DBCC CHECKIDENT ({0}, RESEED, 0)", YourTableName);

happy starting at Id zero!

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.