我试图将数据从一台服务器转移到另一台服务器作为一次性练习,我设置了链接服务器,但我仍然遇到身份字段问题
SET IDENTITY_INSERT Regions On
INSERT INTO Regions SELECT * FROM ARACHNE.CMT.dbo.Regions
SET IDENTITY_INSERT Regions Off
每当我运行上面的脚本时,它都会出错
Msg 8101, Level 16, State 1, Line 2
An explicit value for the identity column in table 'Regions' can only be specified when a column list is used and IDENTITY_INSERT is ON.
但如果运行SET IDENTITY_INSERT Regions On
或SELECT * FROM ARACHNE.CMT.dbo.Regions
,我会得到成功的回复。
我已经检查了目标服务器上用户的权限(这是我尝试执行此查询的位置),并且它具有插入数据和转换identity_insert的正确权限
答案 0 :(得分:4)
错误在于您必须指定列列表;
INSERT INTO Regions (Col1, Col2, Col3) SELECT Col1, Col2, Col3 FROM ARACHNE.CMT.dbo.Regions