Refreshing user views

Modified on Mon, 20 Apr at 12:48 AM

Synergetic use the sp_refreshview to update all standard views as part of every upgrade.

However we don't do this for user views as they may be written in such a way as to cause our database patcher to fail.

This can happen when a view is written using a SELECT * rather than explicit field names, or where a view references base tables or fields that no longer exist.

If required, you can run the following script to refresh views on an as-required basis. However we recommend re-writing any views to make them explicit in what they return.

-----------------------------------------------------------------------------
-- REFRESH ALL VIEWS
-----------------------------------------------------------------------------

SET NOCOUNT ON
DECLARE @SQL varchar(max) = ''
SELECT @SQL = @SQL + 'print ''Refreshing --> [' + name + ']''

EXEC sp_refreshview [' + name + '];
'
 FROM sysobjects 
 WHERE type = 'V' and name like 'uv%' --< condition to select all views, may vary by your standards

EXEC(@SQL)
GO

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article