sobsinha
sobsinha

Reputation: 111

insert issues in an auto increment column

How can I insert data into a column which has been defined as auto increment column using identity insert?please explain with an example.

Upvotes: 4

Views: 2714

Answers (1)

marc_s
marc_s

Reputation: 755531

If you have an "auto-increment" column - you really shouldn't be inserted specific values into that column yourself - after all, that's why it's an auto-increment column....

If you must do so after all - then you need to do:

SET IDENTITY_INSERT (your table name here) ON

INSERT INTO (your table name here) (IdentityCol, OtherCol1, .....)
VALUES( (new ID value), .......)

SET IDENTITY_INSERT (your table name here) OFF

Upvotes: 4

Related Questions