views:

196

answers:

1

Due to dependencies, if I DROP all my stored procs then CREATE, if a proc is missing when another proc that depends on it is created, the procedure is still created but with a warning along the lines of "cannot add rows to sysdepends... procedure will still be created".

That's all fine. However, if we do the same thing with Views, the View fails to be created with error "Invalid Object name..."

My question is simply, why the difference between behaviour for Views and stored procedures- and is there any way to get the procedure behaviour for views?

A: 

I'm kind of guessing here so take it with a grain of salt. Think of a view as a virtual table. Usually a combination of a few to many tables that in memory looks and acts like a regular table in some respects. You can even assign permissions to it. Think of a stored as a paragraph of code. You can create code that has errors in it, but you cannot link tables to tables or views to views, or views to tables if one side of the linking is not there. If I say create a view that links two views together, but one is not created it yet it wouldn't even know what to link with what. I run into this all the time. There may be a better way, but I always just make sure my script creates the views in the correct order so that all will be there when they should be. Also, I haven't tried this personally, but can't you create a view via a stored proc? CREATE VIEW AS blah blah. I hope my ramblings helped in some respect... :)

Rank Beginner
Thanks for your answer. Your ramblings ;-) did help me think about views slightly differently to the way I had been thinking, so it all makes a bit more sense in my head now- thanks
DannykPowell