Empty table data and reset IDENTITY columns

后端 未结 2 2034
别那么骄傲
别那么骄傲 2021-02-19 04:30

I created a database in SQL Server with a couple of tables. I ran some tests and now am ready to deploy my solution, problem is, there is all sorts of data in the tables. I want

相关标签:
2条回答
  • 2021-02-19 04:42

    From: http://www.howtogeek.com/howto/database/reset-identity-column-value-in-sql-server/

    To set the value of the next ID to be 1, I can use this command:

    DBCC CHECKIDENT (orders, RESEED, 0)
    
    0 讨论(0)
  • 2021-02-19 04:49

    You can try TRUNCATE TABLE which deletes all rows and resets identity seeds. However you will have to execute in a certain order if you have foreign keys. In which case you will need to delete from the child tables first, or drop the constraints and re-add them.

    Also note that if you are using IDENTITY you really shouldn't expect the numbers to mean anything, or to be generated forever without gaps. You shouldn't care whether it starts at 1 vs. 22 or 65 - can you explain why the identity values need to be reset?

    0 讨论(0)
提交回复
热议问题