jeudi 18 décembre 2014

INSERT INTO SELECT OPENQUERY() failing with PK conflict


I'm trying to pull rows from a View in MySQL (via a Linked Server) into a local SQL Server table which is basically a local table with a table structure that "mirrors" the view. The following code is giving me an error:


INSERT INTO Forms.dbo.PRIMARYINQUIRY_TLOCAL SELECT * FROM OPENQUERY(LINKEDSERVER_MYSQL,'SELECT * FROM PrimaryInquiry_VIEW')


The error it's giving me refers to a PRIMARY KEY constraint:


Violation of PRIMARY KEY constraint 'PK_PrimaryInquiry_TLOCAL'. Cannot insert duplicate key in object 'dbo.PrimaryInquiry_TLOCAL'.


But the rows I'm pulling in shouldn't be causing a conflict PK conflict.


Here's the result of SELECT * FROM OPENQUERY(LINKEDSERVER_MYSQL,'SELECT * FROM PrimaryInquiry_VIEW'):


enter image description here


I'm trying to put these records into the following local table:


enter image description here


What I've highlighted above is the only column specified as the primary key for Forms.dbo.PRIMARYINQUIRY_TLOCAL, so I'm not sure why I'm getting a conflict when attempting the INSERT INTO


This code only works if I DELETE all records from Forms.dbo.PRIMARYINQUIRY_TLOCAL


Any help would be great!





Aucun commentaire:

Enregistrer un commentaire