0

What is the difference between compile errors and run-time errors in SQL Server? How these errors are distinguished in SQL Server?

jrara
  • 16,239
  • 33
  • 89
  • 120

1 Answers1

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