Quantcast
Channel: SCN: Message List - SAP Adaptive Server Enterprise (SAP ASE) for Custom Applications
Viewing all articles
Browse latest Browse all 3587

Re: DDL in Tran Option - Still a bad idea?

$
0
0

Thank you Rob and Jeff. I have been off for a few days since submitting this and I am just getting back.

 

I had never used this option before and I have done some tests which actually validated the scope of which ddl in tran works with stored procedures.

 

So if the tran  is created within the procedure it is allowed as you can see below. However, as you both have indicated, if the transaction is called outside of the procedure this is not allowed and I am afraid this is what the developers are attempting to do. Every procedure that updates data is wrapped in a transaction and this I am afraid is not allowed.

 

Test 1

=================================

create procedure dbo.usp_test_ddl_in_tran

as

begin

     set nocount on

     begin tran

     create table #temper

     (

       name  varchar(20) not null,

       amount int not null      

     )

    

     insert into #temper values ('Andy',1)

     insert into #temper values ('Mike',2)

     insert into #temper values ('Molly',3)

    

     select name, amount from #temper

    commit tran

    -- insert into trantest values (getdate())

   

end

go

 

select trancount = @@trancount

go

exec usp_test_ddl_in_tran

go

select trancount = @@trancount

go

 

Result

trancount

---------

0       

 

 

name amount

----- ------

Andy 1   

Mike 2   

Molly 3   

 

 

trancount

---------

0

 

Test 2

===========================

begin tran

-- select trancount = @@trancount

 

 

exec usp_test_ddl_in_tran

go

commit tran

go

-- select trancount = @@trancount

-- go

 

nameamount
----------
Andy1   
Mike2   
Molly3   

 

 

Transaction count after EXECUTE indicates that a COMMIT or ROLLBACK TRAN is missing. Previous count = 1, Current count = 0.                                                                                                                                                                                                                         
Number (277) Severity (16) State (1) Server (prod_support) Procedure (usp_test_ddl_in_tran) There was a transaction active when exiting the stored procedure 'usp_test_ddl_in_tran'. The temporary table '#temper' was dropped in this transaction either explicitly or implicitly. This transaction has been aborted to prevent database corruption.

 

The developers are using the second method for all procedures that update data in the database.

 

Thanks again


Viewing all articles
Browse latest Browse all 3587

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>