Question

I am using SQL Server 2008 and SSMS 2012. I have a stored procedure that references a table that does not exist. The editor displays red underlines on the offending table to indicate that something is wrong.

However when I execute the query, I get the message

Command(s) completed successfully.

This is extremely annoying. I also connected to the engine from another machine and it experienced the same problem, which implies its on the server, not ssms. Is there some kind of setting on the database that determines whether the database checks the syntax of stored procedures? PLEASE HELP!

Clarification: I know that the syntax is wrong. The problem is that SSMS allows me to execute the CREATE or ALTER statement without error even when it references a table that does not exist. I want it to fail. Usually it does, but for some reason it suddenly stopped giving errors. I want it to give me errors. How do I do this?

Était-ce utile?

La solution

What's going on is that the IDE in the management studio hasn't had the schema model refreshed. Since the local instance of SSMS doesn't know the table exists, it throws a redline under the table name; when you actually run the sproc/query, the code sent to the database evaluates properly and runs.

To refresh the SSMS local data, try pressing Ctrl-Shift-R, as described here.

Edit:

You might want to look into Deferred Name Resolution

Autres conseils

Your syntax is fine and that is checked when you create the stored procedure. The existence of tables is however not checked until the stored procedure is compiled and that happens when the stored procedure is executed.

You will not get an error message when you CREATE or ALTER, but you can check your SPs for missing dependencies with a script afterwards.

Please check my answer to the related question here (I just post a link to avoid duplication):

I'm looking for a reliable way to verify T-SQL stored procedures. Anybody got one?

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top