Turn: SQL server self-incrementing identity initialization

Reprint link: http://www.th7.cn/db/mssql/201309/34398.shtml

Reprinted content (personal test with minor modifications):

 

Reset the self-incrementing identity column of the ArimaIndexForecastModel table to 0, provided that the table has been deleted, that is, there is no data in the table, otherwise the initialization will fail.

Example:  dbcc checkident('ArimaIndexForecastModel',reseed,0)

Syntax:

DBCC CHECKIDENT ( table_name[, { NORESEED | { RESEED [, new_reseed_value ] } } ])[ WITH NO_INFOMSGS ]

table_name table name, must contain the identity column, otherwise an error will be reported

NORESEED does not change the identity column

RESEED changes the identity column to the specified value

new_reseed_value new value

WITH NO_INFOMSGS does not display the execution result

Reset method:
1. There is data in the table


1. DBCC CHECKIDENT ('ArimaIndexForecastModel', NORESEED) can determine the current maximum value in the column, such as 145, and then execute DBCC CHECKIDENT ('ArimaIndexForecastModel', RESEED, 145), so that the value of the identity column is set to 145, and then add data The value of the identity column starts at 146. The previous data ID column values ​​are unchanged.

 


2. Directly execute DBCC CHECKIDENT ('ArimaIndexForecastModel', RESEED, 0), then execute DBCC CHECKIDENT ('ArimaIndexForecastModel', RESEED) to correct it, and start inserting data from the last value in the table + 1.

Second, there is no data in the table

directly Execute DBCC CHECKIDENT ('ArimaIndexForecastModel', RESEED, 0), the number 0 can be replaced with other numbers

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326535367&siteId=291194637