SQL Server self-increment ID inserts the specified data

Source: Internet
Author: User

Set Identity_insert  on -- allows the insertion of specified data on the self-increment column ID Insert  into Values (1,'test') Set Identity_insert OFF -- turn off insert specified data on the self-increment column ID

Attention:

1.set Identity_insert is only valid for the current session.

2.set identity_insert table name on settings, you must display the specified ID, or insert the error. If INSERT into table_name values (' 111 ') will be an error.

Inserts the specified value to the self-increment ID. Error: " cannot insert an explicit value for the Identity column in table" When IDENTITY_INSERT is set to OFF .

The INSERT statement does not display the specified ID. Error: "You can specify an explicit value for the identity column in the table only if the column list is used and Identity_insert is on."

SQL Server self-increment ID inserts the specified data

Related Article

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.