Domanda

I'm getting an error in the following OPENQUERY statement that I'm trying to execute against a MySql database from SQL Server.

UPDATE OPENQUERY(MYWPDB, 'SELECT total FROM wp_tt WHERE id = 112121') SET total = 1

The error is "Key column information is insufficient or incorrect. Too many rows were affected by update".

The statement should be updating the 'total' field to the value of '1'. It's an integer field and 'id' is the primary key on the table. I'm using SQL Server 2000.

È stato utile?

Soluzione 2

Turns out there's nothing wrong with the query. I was trying to execute the statement inside a cursor operation inside a stored procedure. I tested it outside the cursor operation and it processed fine.

However, since I still needed it to work within the cursor, I had to keep digging, and finally found the four-part syntax would do the trick. So the query instead became:

UPDATE MYWPDB...wp_tt SET total = 1 WHERE id = 112121

Altri suggerimenti

I had the same issue with an openquery that updates iSeries. My openquery is within a cursor also. The fix is to include the key columns in the select.

So in your case it would be something like this:

UPDATE OPENQUERY(MYWPDB, 'SELECT key1, key2, total FROM wp_tt WHERE id = 112121') SET total = 1
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top