📜  T-SQL AZURE Reseed - SQL (1)

📅  最后修改于: 2023-12-03 15:20:26.903000             🧑  作者: Mango

T-SQL AZURE Reseed - SQL

Introduction

In this guide, we will discuss the T-SQL AZURE reseed command and its usage in SQL Server. The reseed command is used to reset the identity value of an identity column in a table. This can be useful when you want to reseed the identity column after deleting records or when you want to start the identity value from a specific number.

Syntax

The syntax for the reseed command is as follows:

DBCC CHECKIDENT ([table_name [, { NORESEED | { RESEED [, new_seed_value ] } }]])
  • table_name: Specifies the name of the table.
  • NORESEED: Specifies that the identity value should not be reseeded.
  • RESEED: Specifies that the identity value should be reseeded.
  • new_seed_value: Specifies the new value to be used as the identity value.
Examples

Let's look at some examples of using the reseed command.

  1. Reseeding with a specific value:
DBCC CHECKIDENT ('employees', RESEED, 100)

This command reseeds the identity value for the 'employees' table to 100. The next record inserted will have an identity value of 101.

  1. Reseeding without specifying a value:
DBCC CHECKIDENT ('employees', RESEED)

This command reseeds the identity value for the 'employees' table to the current maximum value in the table plus one. The next record inserted will have an identity value one higher than the current maximum.

  1. Disabling reseeding:
DBCC CHECKIDENT ('employees', NORESEED)

This command disables reseeding for the 'employees' table. The identity value will not be affected, and the next record inserted will continue with the current identity value.

Conclusion

T-SQL AZURE reseed command is a powerful tool for resetting the identity value of an identity column in SQL Server. By using this command, you can easily manage and control the identity values in your tables. Remember to use it wisely and consider the consequences before reseeding or disabling reseeding.