Microsoft version:
Microsoft described this as "used to update the metadata of the specified view not bound to the architecture. Due to changes to the basic object on which the view depends, the persistent metadata of the view will expire .", I didn't understand the first half of the sentence.
USE AdventureWorks;GOSELECT DISTINCT 'EXEC sp_refreshview ''' + name + '''' FROM sys.objects AS so INNER JOIN sys.sql_expression_dependencies AS sed ON so.object_id = sed.referencing_id WHERE so.type = 'V' AND sed.referenced_id = OBJECT_ID('Person.Contact');
'Person. contact' is the basic table we modified. Refresh all views dependent on this table.
Get a similar
Exec sp_refreshview 'view1'
Exec sp_refreshview 'view2'
Exec sp_refreshview 'view3'
Exec sp_refreshview 'view4'
This list is copied and executed manually.
Network Version:
CREATE PROCEDURE RefreshAllView ASDECLARE MyCursor CURSORFOR select Name from dbo.sysobjects where OBJECTPROPERTY(id, N'IsView') = 1 and (not name in ('sysconstraints','syssegments'))DECLARE @name varchar(40)OPEN MyCursorFETCH NEXT FROM MyCursor INTO @nameWHILE (@@fetch_status <> -1)BEGIN IF (@@fetch_status <> -2) begin exec sp_refreshview @name end FETCH NEXT FROM MyCursor INTO @nameENDCLOSE MyCursorDEALLOCATE MyCursor
Network from: http://www.cnblogs.com/yashen/archive/2004/12/23/81000.html
Generates a stored procedure and automatically refreshes all views.