Wednesday, March 21, 2012

Reset autoincrement number

I use Microsoft SQL Server and also I have several tables. One table has ID like PK, and name. ID use autoincrement number mode, and now when I want start form one but not from 156 or like that. I don't know how? And also when I delete all data from table an run my apllication and add something in table, it starts form last number, not from one.

Maybe can I do it from SQL menagement studio?

How I can reset table and start from 1?Hi,

have a look in the BOL for the following command:

DBCC CHECKIDENT ('HumanResources.Employee', RESEED, 30)

HTH, Jens K. Suessmeyer.

http://www.sqlserver2005.de|||

One way to delete the data AND also reset the IDENTITY field is to TRUNCATE the table. (Check in Books Online, topic: Truncate.)

However, this may not be available if the table has PK-FK relationships with other tables.

|||Hmmm, but my table has PK-FK relationship. What now? Really I don't know how!|||If you want to truncate the table you will HAVE TO break the FK-PK first, othwerwise you will have to delete in the logical parent-child order.

HTH, Jens K. Suessmeyer.

http://www.sqlserver2005.de

No comments:

Post a Comment