December 24, 2013 at 7:58 am
Hi guys, this is a pretty basic question, but I'm hoping someone can provide a little clarity for me. I'm a little confused on how SQL Server binds objects when compiling a stored procedure. For example:
1) If you create a stored procedure that selects from a table that doesn't exist, it'll compile fine and when you run the proc you'll get an error the object doesn't exist.
2) If you create a stored proc that selects from a table that does exist, but you name a column that's not there, you get an error and it doesn't let you compile the procedure at all.
What's going on behind the scenes here? Does SQL Server check to see if the object exists, and if it does it verifies the column names, and if the object doesn't exist it lets you compile it?
Appreciate any feedback you can provide.
Thanks.
December 24, 2013 at 8:11 am
I think the dependency is assumed to be correct if the object does not exist.
Probably to allow to build install scripts that don't have the exact order of dependancy 🙂
December 24, 2013 at 8:43 am
cboneill181 (12/24/2013)
Does SQL Server check to see if the object exists, and if it does it verifies the column names, and if the object doesn't exist it lets you compile it?
Exactly that.
If the table had to exist, you wouldn't be able to run a proc that creates and uses a temp table
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
December 24, 2013 at 8:48 am
Great, thanks for the clarification.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply