问题
What is the difference between compile errors and run-time errors in SQL Server? How these errors are distinguished in SQL Server?
回答1:
compile errors occur during the process of generating an execution plan. Run time errors occur when the plan is generated and is being executed.
The only way of distinguishing between the two is whether or not a plan is generated AFAIK.
Examples
/*Parse Error*/
SELEC * FROM master..spt_values
GO
/*Bind Error*/
SELECT * FROM master..spt_values_
GO
/*Compile time - constant folding error*/
SELECT LOG(0)
FROM master..spt_values
GO
/*Runtime Error*/
DECLARE @Val int = 0
SELECT LOG(@Val)
FROM master..spt_values
The last 2 raise exactly the same error even though one is a compile time error and the other a run time error.
来源:https://stackoverflow.com/questions/8356244/difference-between-compile-errors-and-run-time-errors-in-sql-server