首页 > 代码库 > 批量执行视图

批量执行视图

--由于更新表(例如添加一个字段)后,视图不会自动更新,通过以下脚本可以更新所有的视图:
SELECT N‘EXEC sp_refreshview ‘
+ QUOTENAME(VIEW_NAME, ‘‘‘‘) + ‘;‘ AS cmd
FROM (SELECT QUOTENAME(TABLE_SCHEMA)
+ N‘.‘ + QUOTENAME(TABLE_NAME) AS VIEW_NAME
FROM INFORMATION_SCHEMA.VIEWS) AS V
WHERE OBJECTPROPERTY(OBJECT_ID(VIEW_NAME), ‘IsSchemaBound‘) = 0;
GO

批量执行视图