Search code examples
sql-serverviewprecompiled

Is there a setting in SQL Server to always recompile views on each run?


Having once again been bitten by SQL Server not updating all views properly when you add a field to an underlying table (whaaaaaat!), I am wondering if there is a setting in SQL Server that forces it to recompile the view on every use. Then I could switch this on while doing updates and then when done switch it off again.


Solution

  • There is no automated way that I know off

    Take a look at how to make sure that the view will have the underlying table changes by using sp_refreshview

    What you can do is create the view with SCHEMABINDING, that way nobody can modify the tables without dropping the view first.