当 IDENTITY INSERT 设置为 OFF 时,不能为表 'tb MyInvoices' 中的标识列插入显

               

默认情况下,IDENTITY_INSER就是off这种情况下,你写insert 语句时,identity栏位,不要写值,系统会自动帮你写入。举例说明:create table #aa(id int identity(1,1),dt datetime,pay int)goinsert into #aa(dt,pay)values('2012-4-12',100) --不能向 id栏位写值,系统会自动写goinsert into #aa(id,dt,pay)values(100,'2012-4-14',200) --如果像这样写了,就会报错go如果你需要写,可以把off改成on。如:set IDENTITY_INSERT #aa on insert into #aa(id,dt,pay)values(100,'2012-4-14',200) --这样就不会报错了。实际应用,应该不会要这样,一般设为 identity,就是要利用系统自动写入的功能,保证不重复。
在mapper.xml的插入代码加上  
set IDENTITY_INSERT #aa on 
           

猜你喜欢

转载自blog.csdn.net/qq_44910516/article/details/89281010