开发者

Copying tables one database to the other

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 confl开发者_JAVA技巧icted 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 Transactions table that has a CustomerId referencing the table dbo.Customers (on the column CustomerId) that doesn't exist in the customers table.

Obviously, there is a foreign key relationship between Transactions and Customers and your INSERT statement is violation that referential integrity.

Most likely, you a) haven't synchronized your Customers table between the two servers (yet), or b) you missed some entries somehow.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜