Compilation Error in a Statement Batch in SQL Server

Q

What happens to a Transact-SQL statement batch if there is a compilation error?

✍: FYIcenter.com

A

If a Transact-SQL statement batch has multiple statements, and one of them has compilation error, none of the statements in the batch will be executed. The tutorial exercise below gives you some good examples:

SELECT getdate();
SELECT getdates();
SELECT getdate();
----------------------------
Msg 195, Level 15, State 10, Line 2
'getdates' is not a recognized built-in function name.

As you can see, the compilation error on the second statement stops the execution of all statements.

 

General Questions on Microsoft SQL Server Transact-SQL

⇒⇒SQL Server Transact-SQL Tutorials

2017-05-29, 200👍, 0💬