Pages

Sunday, May 3, 2009

Insert Values into IDENTITY column using IDENTITY_INSERT in SQL Server

In this article i would like show you how to insert values into IDENTITY column.


CREATE TABLE TEST(TEST_ID INT IDENTITY(1,1),TEST_CASE VARCHAR(20))
Command(s) completed successfully.

INSERT INTO TEST(TEST_CASE) VALUES('Login Verification');
INSERT INTO TEST(TEST_CASE) VALUES('Password Verify');
INSERT INTO TEST(TEST_CASE) VALUES('Loging Error Message');


SELECT * FROM TEST

SET IDENTITY_INSERT TEST ON
Command(s) completed successfully.


INSERT INTO TEST(TEST_ID,TEST_CASE) VALUES(5,'PWD Error Message');
(1 row(s) affected)


SELECT * FROM TEST






SET IDENTITY_INSERT TEST OFF

Command(s) completed successfully.

Related Articles:

How to Add Identity to Existing Column

Create Table with Identity in SQL Server

Identity in SQL Server - Alter Identity Column in SQL Server

No comments: