Stop large queries from running

  • Hi,

    I have a query window with a lot of code but I do not want to run it entirely in error, is there something I can place in the beginning of the code that will throw me a message?

    Thanks,

    Akber.

  • akberali67 (3/18/2013)


    Hi,

    I have a query window with a lot of code but I do not want to run it entirely in error, is there something I can place in the beginning of the code that will throw me a message?

    Thanks,

    Akber.

    To return a message to caller during T-SQL code execution you can use PRINT command.

    To throw an error use RAISERROR, together with using BEGIN TRY .. CATCH, it will immediately re-direct code into error handling section.

    Problem with PRINT, is that the message is not guaranteed to be returned at the exact moment of execution of the command, as it has a low processing priority, you may find that messages are returned at the end of the whole code execution.

    RAISERROR causes immediate termination of the process when used with TRY ... CATCH.

    There is one more option:

    RAISERROR ('Return message immidiately', 10,1) WITH NOWAIT;

    The above command raises error with such low severity which doesn't transferring control to the CATCH block making RAISERROR to behave exactly as PRINT (you can use formatting capability of RAISERROR there). WITH NOWAIT hint makes this command to execute with highest priority, so you will get message back as soon as execution hits this line.

    _____________________________________________
    "The only true wisdom is in knowing you know nothing"
    "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]

  • akberali67 (3/18/2013)


    Hi,

    I have a query window with a lot of code but I do not want to run it entirely in error, is there something I can place in the beginning of the code that will throw me a message?

    Thanks,

    Akber.

    The easiest thing to put at the top would be a simple select query referencing a table that does not exist.

    Something like SELECT * FROM Table_That_Does_Not_Exist.

  • sestell1 (3/18/2013)


    akberali67 (3/18/2013)


    Hi,

    I have a query window with a lot of code but I do not want to run it entirely in error, is there something I can place in the beginning of the code that will throw me a message?

    Thanks,

    Akber.

    The easiest thing to put at the top would be a simple select query referencing a table that does not exist.

    Something like SELECT * FROM Table_That_Does_Not_Exist.

    I always use a close parentheses ")" at the top of my code sheets (be careful if you add a go it may not work exactly, tend not to break any thing into batches except in roll out scripts.) This generates a parse error and stops the batch from running.


    For faster help in answering any problems Please read How to post data/code on a forum to get the best help - Jeff Moden[/url] for the best way to ask your question.

    For performance Issues see how we like them posted here: How to Post Performance Problems - Gail Shaw[/url]

    Need to Split some strings? Jeff Moden's DelimitedSplit8K[/url]
    Jeff Moden's Cross tab and Pivots Part 1[/url]
    Jeff Moden's Cross tab and Pivots Part 2[/url]

  • Thanks so much for all the help, I really appreciate your time. The select statement seems to be the most risk free ofcourse and works best for me. Cheers!

  • CapnHector (3/18/2013)


    I always use a close parentheses ")" at the top of my code sheets (be careful if you add a go it may not work exactly, tend not to break any thing into batches except in roll out scripts.) This generates a parse error and stops the batch from running.

    Simple and effective, I like it!

  • sestell1 (3/19/2013)


    CapnHector (3/18/2013)


    I always use a close parentheses ")" at the top of my code sheets (be careful if you add a go it may not work exactly, tend not to break any thing into batches except in roll out scripts.) This generates a parse error and stops the batch from running.

    Simple and effective, I like it!

    That or SELECT * FROM FakeTable will only stop single batch from executing if your script has multiple batches (separated by GO), only the one will be terminated by having such "parse" errors, other batches will not be affected.

    If you want to terminate your script for sure use high severity error:

    RAISERROR ('Stop here',20,1) WITH LOG

    Nothing will pass the above;-)

    _____________________________________________
    "The only true wisdom is in knowing you know nothing"
    "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]

Viewing 7 posts - 1 through 6 (of 6 total)

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