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


Stop large queries from running


Stop large queries from running

Author
Message
akberali67
akberali67
SSC Rookie
SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)

Group: General Forum Members
Points: 25 Visits: 61
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.
Eugene Elutin
Eugene Elutin
SSCertifiable
SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)

Group: General Forum Members
Points: 5214 Visits: 5478
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
sestell1
sestell1
SSCrazy
SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)

Group: General Forum Members
Points: 2575 Visits: 3464
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

.
CapnHector
CapnHector
Ten Centuries
Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)

Group: General Forum Members
Points: 1401 Visits: 1789
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 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

Need to Split some strings? Jeff Moden's DelimitedSplit8K
Jeff Moden's Cross tab and Pivots Part 1
Jeff Moden's Cross tab and Pivots Part 2
akberali67
akberali67
SSC Rookie
SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)

Group: General Forum Members
Points: 25 Visits: 61
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!
sestell1
sestell1
SSCrazy
SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)

Group: General Forum Members
Points: 2575 Visits: 3464
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!
Eugene Elutin
Eugene Elutin
SSCertifiable
SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)

Group: General Forum Members
Points: 5214 Visits: 5478
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
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