patternsqlMinor
Okay to run sp_refreshview against all views on a regular basis?
Viewed 0 times
basisallokayregularagainstsp_refreshviewviewsrun
Problem
Microsoft SQL Server has a system stored procedure called sp_refreshview which updates the metadata of the view that's passed in.
Are there any downsides to running this procedure regularly on all of my views? (Such as performance statistics being affected, etc?)
Could I run it nightly, hourly, every few minutes?
If there's no repercussions in doing so, it seems like a good way to ensure my views metadata stays up to date when there's potential for the underlying entities they reference to change.
Are there any downsides to running this procedure regularly on all of my views? (Such as performance statistics being affected, etc?)
Could I run it nightly, hourly, every few minutes?
If there's no repercussions in doing so, it seems like a good way to ensure my views metadata stays up to date when there's potential for the underlying entities they reference to change.
Solution
there's potential for the underlying entities they reference to change
This is the problem, and you should solve it at the source.
If you are updating objects in the database frequently enough that you have to automate frequent metadata corrections, there is probably an opportunity for better processes.
And you shouldn't be updating tables without also updating the views that reference them. So the views should become part of your schema modification workflow.
You can use
I wrote about this in the following article:
This is the problem, and you should solve it at the source.
If you are updating objects in the database frequently enough that you have to automate frequent metadata corrections, there is probably an opportunity for better processes.
And you shouldn't be updating tables without also updating the views that reference them. So the views should become part of your schema modification workflow.
You can use
WITH SCHEMABINDING on the views, which will explicitly enforce that you can't modify referenced objects without knowingly removing the schema binding. (As an added bonus, your views can't use SELECT *, which is likely part of the problem here).I wrote about this in the following article:
- Benefits of
SCHEMABINDING
Context
StackExchange Database Administrators Q#213218, answer score: 7
Revisions (0)
No revisions yet.