1>
2> CREATE TABLE MyTable (MyID Int IDENTITY(1, 10) NOT NULL
3> , MyDescription nVarChar(50) NOT NULL)
4>
5> INSERT MyTable (MyDescription) VALUES ('Auto Record 1')
6> INSERT MyTable (MyDescription) VALUES ('Auto Record 2')
7>
8>
9> -- Now you explicitly enter a MyID value with the following script:
10>
11> SET IDENTITY_INSERT MyTable ON INSERT MyTable (MyID, MyDescription)
12> VALUES (5, 'Manual Record 1') SET IDENTITY_INSERT MyTable OFF
13>
14> -- SQL Server will always choose the highest number as its current seed for a positive -- increment value or the lowest for a negative increment value
15>
16> INSERT MyTable (MyDescription)
17> VALUES ('Auto Record 3')
18>
19> SELECT * FROM MyTable
20>
21> drop table MyTable
22> 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>
|