Reset Identity column to zero in SQL Server?

前端 未结 6 2323
不知归路
不知归路 2021-02-19 04:36

How can I reset the Identity column of a table to zero in SQL Server?

Edit:

How can we do it with LINQ to SQL ?

6条回答
  •  别那么骄傲
    2021-02-19 05:01

    DBCC CHECKIDENT (MyTable, RESEED, NewValue)
    

    You can also do a Truncate Table, but, of course, that will remove all rows from the table as well.

    To do this via L2S:

    db.ExecuteCommand("DBCC CHECKIDENT('MyTable', RESEED, NewValue);");
    

    Or, you can call a stored procedure, from L2S, to do it

提交回复
热议问题