Setting method for set IDENTITY_INSERT on and off in SQL Server

Source: Internet
Author: User

Set IDENTITY_INSERT on and off in SQL Server:

Execute INSERT Database Insert data times the following error, I clearly did not give the primary key set value but still error

Here's how to fix it:

Qlserver when you insert a record in bulk, set the SET IDENTITY_INSERT table name on the field that has the identity column, and then perform the insert record operation; revert to off setting after insert is complete

Format:
SET IDENTITY_INSERT table name on
SET IDENTITY_INSERT table name off

Example:
SET Identity_insert Peoplepworkpositiontype on
Insert Peoplepworkpositiontype (Id,workpositiontype,workpositiontypeid) VALUES (1, ' Platform ', 1)
Insert Peoplepworkpositiontype (Id,workpositiontype,workpositiontypeid) VALUES (2, ' Land ', 2)
Insert Peoplepworkpositiontype (Id,workpositiontype,workpositiontypeid) VALUES (3, ' Sea ', 3)

Setting method for set IDENTITY_INSERT on and off in SQL Server

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.