sql server - ROLLBACK TRANSACTION used as an undo -


i want create stored proc performs work based on few parameters. destructive work , 1 of parameters reallydoit (y/n)

what i'd create proc so

create proc dosomething @paramone int, @reallydoit char(1) begin  begin try   begin transaction   stuff   logging info   more stuff   add logging info   etc....   if @reallydoit = 'y' commit transaction   else rollback tran end try begin catch  if @@trancount >0 rollback tran end catch 

i'm looking see if appropriate design stored procedure. there i'm missing or can hose if way.

are there situations using method fail or produce unwanted results in data. should instead use separate block of code implement logging if @reallydoit 'n'

i have used design in past in order able unit test stored procedures. approach allows verify row counts without altering data. however, recommend default @reallydoit y stored procedure works correctly once deployed. should make sure not work inside transaction result in heavy load on transaction log , lock tables being updated.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -