Empty table data and reset IDENTITY columns

后端 未结 2 2016
别那么骄傲
别那么骄傲 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: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?

提交回复
热议问题