This SQL statement runs but then halts:
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
but it processes for about 5 minutes and then this error:
Msg 547, Level 16, State 0, Line 4 The
INSERT statement conflicted with the
FOREIGN KEY constraint
“FK_Transactions_Customers”. The
conflict occurred in database “CPI”,
table “dbo.Customers”, column
‘CustomerId’. The statement has been
terminated.
The message is pretty clear: you’re trying to insert a value into the
Transactionstable that has aCustomerIdreferencing the tabledbo.Customers(on the columnCustomerId) that doesn’t exist in the customers table.Obviously, there is a foreign key relationship between
TransactionsandCustomersand your INSERT statement is violation that referential integrity.Most likely, you a) haven’t synchronized your
Customerstable between the two servers (yet), or b) you missed some entries somehow.