--刷新(重新编译)指定数据库中所有的视图/存储过程/触发器/自定义函数declare tb cursor for 
--刷新视图处理的语句
select 'exec sp_refreshview ''['+replace(user_name(uid), N']',N']]')+'].['
+replace(object_name(id),N']',N']]')+']'''
from dbo.sysobjects
where xtype='v' and status>=0
union all --刷新存储过程,自定义函数,触发器的语句
select 'exec sp_recompile ''[' + replace(user_name(uid), N']', N']]')+'].['
+ replace(object_name(id), N']', N']]')+ ']'''
from dbo.sysobjects
where xtype in('tr','fn','if','tf','p') and status>=0declare @s nvarchar(4000)
open tb 
fetch tb into @s
while @@fetch_status=0
begin
exec(@s)
fetch tb into @s
end
close tb
deallocate tb