0

I have a procedure that pushes data from my local SQL Server 2005 database into a table in an Azure DB which is set up as a linked server. The basic data flow is create a #staging table, fill the #staging table with the new data, update existing rows in the Azure table, insert new rows in the Azure table. The error that is returned is "Cursor plan failed because it is not possible to force the plan for a cursor of type other than FAST_FORWARD or STATIC with a USE PLAN hint. Consider removing USE PLAN hint and updating statistics or using different hints to influence query plan choice." however I am not using a cursor in the procedure. I've narrowed the section of code down to the UPDATE portion below.

    UPDATE T1
    SET T1.Col5 = T2.Col5
    FROM
    Azure.database.dbo.tablename T1 INNER JOIN #staging T2
    ON  T1.[col1] = T2.[col1] COLLATE Latin1_General_CI_AS
    AND T1.[col2] = T2.[col2] COLLATE Latin1_General_CI_AS 
    AND T1.[col3] = T2.[col3] COLLATE Latin1_General_CI_AS
    AND T1.[col4] = T2.[col4]
    WHERE T1.[col5] <> T2.[col5]

I'm using the same workflow to maintain a few other tables without issue so I'm not sure what the problem could be. I tried rebuilding statistics on the destination table and recompiling the procedure with no success. Any help would be appreciated.

I tried dropping the table on the Azure side and re-creating it in the hopes that anything cached would be cleared out. Ran the procedure and succeeded but only Inserts were required since the new table was empty. Ran a second time and it failed on the Update section with the same error.

Re-wrote the procedure and replaced Update section with Delete from Azure where key fields found in #staging then Insert from #staging. Working but certainly not ideal.

4
  • Is that the complete script? Commented Oct 3, 2024 at 16:19
  • 2
    No way that error came from that SQL. Has to be from something else nearby. Something with a USE PLAN hint. Commented Oct 3, 2024 at 16:46
  • 2
    I really hope the reason you're doing this is to migrate your database to Azure. SQL Server 2005 reached end of life around a decade ago; using such an old, insecure, version is a severe concern for you, your company, and your customers, and at this point would only be seen as a form of negligence in the event something gors wrong. Commented Oct 3, 2024 at 17:00
  • That is just the section of code that seems to be causing the failure. If I comment out just that section of code the SP runs successfully but as soon as I include it I receive the error after the #staging table is loaded successfully. Commented Oct 3, 2024 at 17:33

1 Answer 1

0

Azure SQL database does not support three- or four-part names when you make reference to a table/object.

In case it is useful to you, Azure SQL Database does not support cross database queries also. You need to configure elastic queries for that.

In addition, my understanding is that Azure SQL Database and its tools (like Data Sync) support SQL Server 2008 R2 and later.

Sign up to request clarification or add additional context in comments.

2 Comments

You are correct that Azure SQL does not support three or four part names however the procedure is being run on the local database which does. The Azure database is set up as a linked server. Also, the same syntax is being used to update 2 other tables in the Azure database without issue. The procedures are almost identical except for the table and column names being referenced.
Could you try the same on a Windows Server 2012 or later? Using a SQL Server driver that supports Azure SQL (at least native client 11.0).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.