Two methods:
One is to use truncate
Truncate table name
You can delete all values in the table and reset the id value.
Second, DBCC checkident
DBCC checkident ('table _ name', reseed, new_reseed_value)
For example, DBCC checkident ("bc_pos", reseed, 1) can be used. However, if there is data in the table, the reset value may be faulty if it is smaller than the maximum value.
DBCC checkident ("bc_pos", reseed) can automatically reset the value.
3. Determine whether a table in a segment has an ID column
Available
The objectproperty function determines whether a table has an identity column. Usage:
Select objectproperty (object_id ('table name'), 'tablehasauth ')
If yes, 1 is returned; otherwise, 0 is returned.
4. Determine whether a column is an ID column.
You can use the columnproperty function to determine whether a column has the identity attribute.
Select columnproperty (object_id ('table name'), 'column name', 'isidentity ')
If this column is an identifier column, 1 is returned; otherwise, 0 is returned.
4. query the column names of an identity column in a table.
SQL Server does not have ready-made functions to implement this function. The SQL statements implemented are as follows:
Select column_name from information_schema.columns
Where table_name = 'table name' and columnproperty (
Object_id ('table name'), column_name, 'isidentity ') = 1
5. Identify column reference
If you reference the ID column in an SQL statement, use the keyword identitycol instead.
For example, to query the rows in the previous example with the ID equal to 1,
The following two query statements are equivalent.
Select * From t_test where identitycol = 1
Select * From t_test where
6. Obtain the seed value of the ID column
You can use the ident_seed function. Usage:
Select ident_seed ('table name ')
7. Get the increment of the ID column
You can use the ident_incr function. Usage:
Select ident_incr ('table name ')
8. Obtain the last generated id value in the specified table.
the ident_current function can be used. Usage:
select ident_current ('table name')
note: when the table that contains the ID column is just created and any insert operation is performed, the value obtained by using the ident_current function is the seed value of the ID column, pay special attention to this when developing database applications.