SQLServer插入数据到有自增列的表

来源:这里教程网 时间:2026-03-02 11:48:03 作者:

SQLServer插入数据到有自增列的表报错:仅当使用了列列表并且 IDENTITY_INSERT 为 ON 时,才能为表'Sales.dbo.Area'中的标识列指定显式值。 正确方式:

set IDENTITY_INSERT Sales.dbo.Area ON
insert into Sales.dbo.Area(
[SysNo],
[DistrictSysNo],
[DistrictName]
)
select [SysNo],
[DistrictSysNo],

[DistrictName]

from opsdb.dbo.Area

跨服务器,可以用linkserver: set identity_insert  [Customer_Log]  on insert into   Customer..Customer_Log (     [SysNo]       ,[CustomerSysNo]   )     select         [SysNo]       ,[CustomerSysNo]     from       [192.168.0.34].yy.dbo.Customer_Log  with(nolock)     where       sysno < 2013422222      set identity_insert  [Customer_Log]  off

相关推荐