Mega Code Archive

 
Categories / MSSQL Tutorial / Sequence Indentity
 

The IDENTITY property must be temporarily turned off when inserting a specific value

9>  CREATE TABLE MyTable (MyID Int IDENTITY(-1000000, 100) NOT NULL 10>            ,MyDescription NVarChar(50) NOT NULL) 11> GO 1> 2> SET IDENTITY_INSERT MyTable ON 3> 4> INSERT MyTable (MyID, MyDescription) 5> VALUES (5, 'This will work') 6> 7> SET IDENTITY_INSERT MyTable OFF 8> 9> select * from MyTable; 10> GO (1 rows affected) MyID        MyDescription ----------- --------------------------------------------------           5 This will work (1 rows affected) 1> 2> drop table MyTable; 3> GO