Stop Script Execution

  • I frequently develop scratch sql scripts in Management Studio - as a single file - and only run small portions of the total - using highlight CTRL+E. this works fine and I find it a fast way to develop ideas. But occasionally I make mistakes and sometimes execute the whole script unitentionally. I'd like to put a statement at the top of the file which would prevent the script executing.

    This is complicated by the script containing GO statements - which are required if part of my code contains a DROP/CREATE PROC or DROP/CREATE FUNCTION

    I've tried RAISERROR,

    I've tried starting with BEGIN TRAN and ending with ROLLBACK

    I've tried starting with GOTO label and ending with label:

    Its the GO statement thats causing the problem - I can stop execution up to the first GO - anything beyond will then run unfettered.

  • No, the client tools handle the GO batch separator, so the individual batches are sent to the server. There is no way to do what you are suggesting, but as another option, you can turn the SET IMPLICIT_TRANSACTIONS option on in Management studio so BEGIN TRAN is issued and you would have to explicitly commit your transactions.

  • Thanks,

    I've decided to put USE TEMPDB at the top of my script files - followed by a RAISEERROR as a harm reduction strategy in case of accidental execution

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply