Friday, 10 December 2010

Refresh a View

Many time we use “Select *” in our view definition or say in view query.
 Well although it’s not a good practice but some time it can be handy as well.
If In your table column are changing and you have view on it than having “SELECT *” is not a bad idea,
As views are static in SQL SERVER   having “SELECT *” will not reflect the changes you made to your tables.  So whenever column changes (removed/addition) you will get an error while retrieving data from Views.
To fix your views for this problem quickly You can use Stored Procedure Sp_RefreshView to refresh your views.
sp_refreshview [ @viewname= ] 'viewname'

This will refresh the view defination and you will be able to pull data from your view. 

No comments:

Post a Comment