November 17, 2014 at 5:16 am
I have a growing number of views which are all returning the same fields with a different where criteria. If I need to add a new field I need to add it to all these views. So I came up with the great idea of having one view I could add fields to when required and then point all the other views as a select * from view where . . . However when the view saves it looks like it replaces the * with the field names at the point of saving. Is there any way around this ?
November 17, 2014 at 5:45 am
Using "SELECT * " in a view has a caveat you need to be aware of or it will bite you in the ***. A change in columns of the underlying object does NOT propagate automatically. You need to use sp_refreshview to re-compile the view to use the new field structure.
November 17, 2014 at 6:09 am
... and recompile inline TVFs of that kind (return Select * ...) too. If you just hoped to go this way. 🙂
November 17, 2014 at 7:36 am
And be warned...when building views that call views you are highly likely to get suboptimal execution plans. In short, performance is going to start degrading when you nest views.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply