When does execution stop?

  • create table test(c1 int, c2 int)

    create unique index idx_test on test (c1)

    insert test values (1, 2)

    insert test values (1, 2)

    select * from test--still executes

    insert test select c1/0, 4 from test

    select c1 * 10, c2 * 10 from test--still executes

    select * from I_Dont_Exist--execution halted

    select * from test

    create unique index idx_test on test (c2)

    select * from test

    Obviously this is simplified and contains no error handling but there are times when you come across code in old procs or you want to run a list of adhoc statements. How can you otherwise tell when it erred out given the error message, level, and state from SQL?

    Thanks,

    Ken

  • I'm not quite sure I follow. Are you asking for an alternative to explicit error handling?

  • nope I dont understand that either, can you give more details?

    --------------------------------------------------------------------------------------
    [highlight]Recommended Articles on How to help us help you and[/highlight]
    [highlight]solve commonly asked questions[/highlight]

    Forum Etiquette: How to post data/code on a forum to get the best help by Jeff Moden[/url]
    Managing Transaction Logs by Gail Shaw[/url]
    How to post Performance problems by Gail Shaw[/url]
    Help, my database is corrupt. Now what? by Gail Shaw[/url]

  • Usually, but not always, when you run the query in SSMS, you will get a line number for the error. But that's a pretty thin reed to hang your troubleshooting on. Otherwise, you'll see an error that describes the statement being processed and you just have to figure out where it is.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • And even then it's a bit tricky. Say you're trying to execute 10 T-SQL commands and you get errors on a couple of them. As you say the lines #'s aren't there or not always useful. It's like, where do I pickup this sequence from to continue?

    In my example message level was sometimes 14 and sometimes 16 but there seems to be no rhyme or reason as to when SQL discontinues it's execution.

    Ken

Viewing 5 posts - 1 through 4 (of 4 total)

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