Identity identity Column

Source: Internet
Author: User

In SQL Server, the identity identity column is often used, and this self-growing field is indeed more convenient to operate. But it sometimes brings some trouble.

Example one: when some data is deleted from the table, the number of the self-increment column is no longer a line-up sequence. At such times we can use the following solutions to solve.

SET Identity_insert [TABLE] [on| OFF]

http://www.cnblogs.com/roucheng/p/GUID.html

Allows an explicit value to be inserted into the identity column of the table, when set to on, the number inserted into the identity column may be manually specified during the insert operation, and the identity_insert must be restored to off after the operation is complete, or the number must be specified the next time the insert is made. Otherwise, you will not be able to complete the insert operation.

Example two: when a record in a table is completely deleted, but when the value of the identity column becomes larger, it will grow indefinitely if not reset. This time we need to use:

DBCC checkident (TABLE, [reseed| Noreseed], [1])

The seed value of the specified table is reset to 1. However, you may not want to reset the seed to 1, in which case you can replace the third parameter with the seed value you want to use. Sometimes you may want to know the current seed, instead of resetting the seed, then you need to use the noreseed instead of worrying about the third argument.

Http://www.cnblogs.com/roucheng/p/earth.html

Identity identity Column

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.