Why the next sql statement can continue to execute after database compilation errors?

Ailsa Ge 41 Reputation points
2021-01-20T03:18:28.78+00:00

The sql stetment in mater database stop runing after raise error ,but in other database it contiue run.
58462-58750f3b-54d1-4bf9-a7a0-0e33ab9341d3.png

58376-5a55a559-e5ae-44df-a890-c6f0806f35d0.png

Developer technologies | Transact-SQL
Developer technologies | Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
{count} votes

Answer accepted by question author
  1. EchoLiu-MSFT 14,626 Reputation points
    2021-01-20T03:51:34.94+00:00

    Hi @Ailsa Ge

    This question has nothing to do with which database you use. In theory, if one statement return an error, the next statement will stop executing. But there are some exceptions.
    In my opinion, it may be understood like this:

    The first step when executing a statement is to find the table to be operated on. When you use the main database, since there is no table [20180521] in the main database, this error is returned first. And this error does not allow the next statement to continue execution, so other statements did not execute successfully.

    When you use the under_group database, the [20180521] table is in the under_group database, so the same error as the main database will not be returned. Next, because the IDENTITY_INSERT property is set to off, data cannot be inserted explicitly. But this error allows the next statement to continue. So other statements are executed successfully.

    If you have any question, please feel free to let me know.
    If the response is helpful, please click "Accept Answer" and upvote it.

    Regards
    Echo


    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.