Mega Code Archive

 
Categories / MSSQL Tutorial / Sequence Indentity
 

Cannot insert explicit value for identity column in table T when IDENTITY_INSERT is set to OFF

4>  CREATE TABLE T ( 5>     int1 int IDENTITY PRIMARY KEY, 6>     bit1 bit NOT NULL DEFAULT 0 7> ) 8> GO 1> 2> INSERT T (bit1) VALUES (1) 3> INSERT T (bit1) VALUES (0) 4> INSERT T DEFAULT VALUES 5> INSERT T (int1, bit1) VALUES (4,1) 6> GO (1 rows affected) (1 rows affected) (1 rows affected) Msg 544, Level 16, State 1, Server J\SQLEXPRESS, Line 5 Cannot insert explicit value for identity column in table 'T' when IDENTITY_INSERT is set to OFF. 1> 2> select * from t; 3> GO int1        bit1 ----------- ----           1    1           2    0           3    0 (3 rows affected) 1> 2> drop table t; 3> GO