I'm using try/catch to detect any errors in my script. If there are no errors then I would like to rename the table at the end of catch and if there are errors then I want to stop it in catch. But when I'm having problem with this. It is renaming the table regardless of errors. Is there any reason for this? I'm assuming try/catch runs the 'exec' statement regardless of errors.
If I understand what you want to do, then you could have a variable to indicate if there was an error. Then set it to True. If your variable is false, rename the table. In hasty psuedo-code it would look like: #declare variables set @therewasanerror = false begin try create table.... do other stuff end try begin catch do your error handling set @therewasanerror = true end catch if not @therewasenrror rename table
You should leave the create table statement within the TRY part of the code, not the CATCH. It should only be going to the CATCH part of the code if there is an actual error. That's how it's meant to work.