SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


BEGIN vs BEGIN TRY


BEGIN vs BEGIN TRY

Author
Message
autoexcrement
autoexcrement
SSCarpal Tunnel
SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)

Group: General Forum Members
Points: 4560 Visits: 1150
I just want to be 100% sure... Do the following two statements execute identically? Meaning, can I use the 2nd one, or do I need the extra BEGIN/END as in the 1st one? Thanks!

IF @blabla > 0
BEGIN
BEGIN TRY
[do lotsa stuff]
END TRY
BEGIN CATCH
[do stuff]
END CATCH
END


IF @blabla > 0
BEGIN TRY
[do lotsa stuff]
END TRY
BEGIN CATCH
[do stuff]
END CATCH



"If I had been drinking out of that toilet, I might have been killed." -Ace Ventura
Lynn Pettis
Lynn Pettis
SSC Guru
SSC Guru (395K reputation)SSC Guru (395K reputation)SSC Guru (395K reputation)SSC Guru (395K reputation)SSC Guru (395K reputation)SSC Guru (395K reputation)SSC Guru (395K reputation)SSC Guru (395K reputation)

Group: General Forum Members
Points: 395414 Visits: 43154
Try them both and see if either or both work. Personally, I would lean to using the first format because of the IF.

Cool
Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
autoexcrement
autoexcrement
SSCarpal Tunnel
SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)

Group: General Forum Members
Points: 4560 Visits: 1150
As far as I can tell, it seems to work the same either way. Just didn't want to accidentally screw this up.


"If I had been drinking out of that toilet, I might have been killed." -Ace Ventura
Lynn Pettis
Lynn Pettis
SSC Guru
SSC Guru (395K reputation)SSC Guru (395K reputation)SSC Guru (395K reputation)SSC Guru (395K reputation)SSC Guru (395K reputation)SSC Guru (395K reputation)SSC Guru (395K reputation)SSC Guru (395K reputation)

Group: General Forum Members
Points: 395414 Visits: 43154
autoexcrement - Friday, November 9, 2018 1:24 PM
As far as I can tell, it seems to work the same either way. Just didn't want to accidentally screw this up.

If you are working in a development or sandbox environment you should screw anything up that can't be fixed. Don't test in production.


Cool
Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
andycadley
andycadley
Hall of Fame
Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)

Group: General Forum Members
Points: 3468 Visits: 1770
Both will work, though I personally prefer the explicit BEGIN/END pair on any IF statement, if only because somebody will come along later and ask the same question about whether that works or not.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum








































































































































































SQLServerCentral


Search