Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Stop large queries from running Expand / Collapse
Author
Message
Posted Monday, March 18, 2013 12:41 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Saturday, September 7, 2013 5:18 AM
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.
Post #1432087
Posted Monday, March 18, 2013 3:24 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Friday, December 12, 2014 10:09 AM
Points: 2,876, Visits: 5,201
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!"
(So many miracle inventions provided by MS to us...)

How to post your question to get the best and quick help
Post #1432116
Posted Monday, March 18, 2013 2:06 PM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Yesterday @ 9:23 AM
Points: 1,422, Visits: 2,444
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

.
Post #1432329
Posted Monday, March 18, 2013 2:21 PM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Friday, September 19, 2014 5:16 AM
Points: 887, Visits: 1,774
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

Jeremy Oursler
Post #1432335
Posted Monday, March 18, 2013 9:53 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Saturday, September 7, 2013 5:18 AM
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!
Post #1432463
Posted Tuesday, March 19, 2013 7:05 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Yesterday @ 9:23 AM
Points: 1,422, Visits: 2,444
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!
Post #1432628
Posted Tuesday, March 19, 2013 7:57 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Friday, December 12, 2014 10:09 AM
Points: 2,876, Visits: 5,201
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!"
(So many miracle inventions provided by MS to us...)

How to post your question to get the best and quick help
Post #1432664
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse