What is the difference between compile errors and run-time errors in SQL Server? How these errors are distinguished in SQL Server?
Asked
Active
Viewed 2,699 times
0
-
1No, I'm not at school anymore... – jrara Dec 02 '11 at 13:13
1 Answers
3
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.

Martin Smith
- 438,706
- 87
- 741
- 845