Mega Code Archive

 
Categories / MSSQL Tutorial / Sequence Indentity
 

SQL Server will choose the highest number as its current seed for a positive increment value or the lowest for a negati

4>  CREATE TABLE MyTable (MyID Int IDENTITY(1, 10) NOT NULL 5>            , MyDescription nVarChar(50) NOT NULL) 6> 7> INSERT MyTable (MyDescription) VALUES ('Auto Record 1') 8> INSERT MyTable (MyDescription) VALUES ('Auto Record 2') 9> 10> SET IDENTITY_INSERT MyTable ON 11> 12> INSERT MyTable (MyID, MyDescription) VALUES (5, 'Manual Record 1') 13> 14> SET IDENTITY_INSERT MyTable OFF 15> 16> INSERT MyTable (MyDescription) VALUES ('Auto Record 3') 17> 18> SELECT * FROM MyTable 19> GO (1 rows affected) (1 rows affected) (1 rows affected) (1 rows affected) MyID        MyDescription ----------- --------------------------------------------------           1 Auto Record 1          11 Auto Record 2           5 Manual Record 1          21 Auto Record 3 (4 rows affected) 1> 2> drop table MyTable; 3> GO