SQL Server – Create or Alter Stored Procedure Without Compiling

sql serversql-server-2005

Is it possible to create or alter a stored procedure in SQL Server 2005* that doesn't compile the procedure?

(* – yes, unfortunately, we still need to support 2005 as our minimum standard)

I have a situation where it would be exceedingly useful to be able to create/alter a stored procedure that is syntactically valid but not semantically valid (due to incorrect table/column names)… which I can then alter accordingly within SSMS.

I've just had a thought, and it's a pretty simple solution… comment out the entire contents of the stored procedure when it's being altered/created.

Using Ctrl+K Ctrl+C will comment out each line individually – which would be better than using /* */ around the entire thing, as that will fail if there are any instances of /* */ in the stored procedure already.

I would still be very interested to hear if there is an actual way to tell SSMS to ignore invalid table/view/column names.

Thanks to @marcelo for his answer, and it does appear that using the name of a non-existent table will allow you to create the stored procedure.

However, it does not allow you to create a stored procedure if you use a non-existent column in an existing table

Best Answer

What you are referring to is deferred name resolution and is further explained here Deferred Name Resolution and Compilation.

Deferred name resolution can only be used when you reference nonexistent table objects. All other objects must exist at the time the stored procedure is created. For example, when you reference an existing table in a stored procedure you cannot list nonexistent columns for that table.

Basically, no you are not able to alter the parsers rules for what objects must exist at parse and compile time. I've previously had this issue when deploying SPs which reference linked servers and those linked servers did not have a valid connection. To work around it I updated the linked sever logic to be dynamic SQL.