Gaurav Jain
Gaurav Jain

Reputation: 1

creating view and procedure for non existense table?

I have one query regards the creating a procedure and view.

Simple :

Create Procedure usp_demoXYZ
As
Begin
Select * from Table1 -- This table is not present in current Database
End

After execute the above query, query is executed successfully and created procedure.

But same things we apply in time of creating View.

Create View Vw_demoXYZ
As
Select * from Table1 -- This table is not present in current Database

after that I m running above query , sql server is showing error..

Msg 208, Level 16, State 1, Procedure Vw_demoXYZ, Line 4

Invalid object name 'Table1'

Upvotes: 0

Views: 15

Answers (1)

Hakunamatata
Hakunamatata

Reputation: 1275

Stored procedures use Deferred Name Resolution while views does not do that. Deferred Name Resolution means when you create a stored proc it only checks if syntax of the statements are correct and not if the objects/tables it is referring to are there in database. That only occurs at runtime when you execute stored proc.

More details can be found here :

https://technet.microsoft.com/en-us/library/ms190686(v=sql.105).aspx

Upvotes: 1

Related Questions