Recently modified the database table structure, the data synchronization problem, found that a lot of data has been modified, but filtered through the view or the original data, so suspect should be the view cache data, in the garden to find the following blog post, here to make a record memo.
original link:http://www.cnblogs.com/yashen/archive/2004/12/23/81000.html
This is often the case when we use SQL Server, and when we modify the structure of a table, the associated view is wrong and the program is wrong, so there is a stored procedure below.
CREATEPROCEDURERefreshAllView ASDECLAREMyCursor CURSORFORselectNamefromdbo.sysobjects whereOBJECTPROPERTY(id, N‘IsView‘) = 1 and(notnamein(‘sysconstraints‘,‘syssegments‘)) DECLARE@namevarchar(40)OPENMyCursorFETCHNEXTFROMMyCursor INTO@nameWHILE (@@fetch_status <> -1)BEGIN IF (@@fetch_status <> -2) begin execsp_refreshview @name end FETCH NEXTFROMMyCursor INTO@nameENDCLOSEMyCursorDEALLOCATEMyCursor |
Bulk update of all views after SQL Server modifies table structure