Synapse SQL drop table within a transaction

Rock, Danny 51 Reputation points
2020-11-16T04:56:19.403+00:00

Hi all,
I am trying to create a transaction in Synapse that I run a stored proc within with the ability to rollback but I keep getting this error when i exec the sp:

Msg 111213, Level 16, State 1, Line 1
111213;The current transaction has aborted, and any pending changes have been rolled back. Cause: 110806;A distributed query failed: Distributed transaction completed. Either enlist this session in a new transaction or the NULL transaction.

The stored proc its trying to execute the following e.g query:

if object_id('[tablea]') is not null
drop table [tablea]

    select 
                 customer
                ,number
                ,invc



    into [tablea]
    from 
    (select * from tableb)
Azure Synapse Analytics
Azure Synapse Analytics
An Azure analytics service that brings together data integration, enterprise data warehousing, and big data analytics. Previously known as Azure SQL Data Warehouse.
4,858 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. HimanshuSinha-msft 19,471 Reputation points Microsoft Employee
    2020-11-17T00:46:11.007+00:00

    Hello @Rock, Danny ,
    Thanks for the ask and also for using the forum .

    This is what I tried , created a proc which just checks if a table exists and if it does it drops it .

    CREATE PROC Testproc  
    AS   
    IF OBJECT_ID('[SINK]') IS NOT NULL  
    DROP TABLE SINK  
    
    BEGIN TRAN   
    	EXEC TESTPROC  
    ROLLBACK TRAN   
    

    I am getting the below error .

    Msg 111212, Level 16, State 1, Line 21
    111212;Operation cannot be performed within a transaction.

    This may be related to this .
    "No support for DDL such as CREATE TABLE inside a user-defined transaction" .

    Let me know if this helps .

    Thanks Himanshu
    Please do consider to click on "Accept Answer" and "Upvote" on the post that helps you, as it can be beneficial to other community members.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.