2

I removed all data from my mdf database by using delete commands. Now when I run program, the primary key on auto increment does not start from 1. Instead it auto increments the last deleted id number.

The primary key should start from 1 after deletion.

Michiel Leegwater
  • 1,172
  • 4
  • 11
  • 27
Umer Saeed
  • 63
  • 4

1 Answers1

1

You need to use the command DBCC CheckIdent

but next time use the TRUNCATE command that deletes the record but resets also the identity

So supposing you have a table named INVOICE and you need to reset its ID to 1

DBCC CHECKIDENT ('INVOICE');  

and when you want to clear that table use

TRUNCATE TABLE INVOICE
Steve
  • 213,761
  • 22
  • 232
  • 286