此SQL语句运行但随后停止:
SET IDENTITY_INSERT [CPI].[dbo].[Transactions] ON
GO
insert into CPI.dbo.Transactions
(customerid = 24, TransactionId, DepartmentId, ItemId, CategoryId, Quantity, Cost, DateCreated, InvoiceNumber, DataSource, DataSourceId, ImportId, LastUpdate)
select customerid = 104, TransactionId, DepartmentId, ItemId, CategoryId, Quantity, Cost, DateCreated, InvoiceNumber, DataSource, DataSourceId, ImportId, LastUpdate
from Analyzer.dbo.transactions
但它会处理约5分钟,然后出现此错误:
Msg 547,Level 16,State 0,Line 4 The INSERT语句与 FOREIGN KEY约束 “FK_Transactions_Customers”。该 数据库“CPI”发生冲突, 表“dbo.Customers”,专栏 '顾客ID'。声明一直如此 终止。
答案 0 :(得分:4)
消息非常清楚:您正在尝试在Transactions
表格中插入一个值CustomerId
来引用表格dbo.Customers
(在CustomerId
列上)在customers表中不存在。
显然,Transactions
和Customers
之间存在外键关系,而您的INSERT语句违反了引用完整性。
最有可能的是,你a)尚未在两台服务器之间同步你的Customers
表,或者b)你错过了某些条目。