當你在自動編號的列插入數據時就要設置成ON。當自動編號列自動產生數據,也就是你不在那列插入數據就設置為OFF,缺省是“OFF”。例: create table Test (RowId int Identity(1,1) not null, EmpName nvarchar(10), Age int) go insert Test values(N'張三',20) //這時缺省為OFF 不用設。 go set identity_insert table on //下條語句要插入RowId為10,此時要先設成ON go insert Test values(10,N'李四',30) go
create table Test
(RowId int Identity(1,1) not null,
EmpName nvarchar(10),
Age int)
go
insert Test values(N'張三',20) //這時缺省為OFF 不用設。
go
set identity_insert table on //下條語句要插入RowId為10,此時要先設成ON
go
insert Test values(10,N'李四',30)
go