DECLARE @Name nvarchar(1000); DECLARE @Sql nvarchar(1000); DECLARE @Result int; DECLARE ObjectCursor CURSOR FAST_FORWARD FOR SELECT QUOTENAME(SCHEMA_NAME(o.schema_id)) + '.' + QUOTENAME(OBJECT_NAME(o.object_id)) FROM sys.objects o WHERE type_desc IN ( 'SQL_STORED_PROCEDURE' ) --include the following if you have schema bound objects since they are not supported AND ISNULL(OBJECTPROPERTY(o.object_id, 'IsSchemaBound'), 0) = 0 ; OPEN ObjectCursor; FETCH NEXT FROM ObjectCursor INTO @Name; WHILE @@FETCH_STATUS = 0 BEGIN SET @Sql = N'EXEC sp_refreshsqlmodule ''' + @Name + ''''; PRINT @Sql; BEGIN TRY EXEC @Result = sp_executesql @Sql; IF @Result <> 0 RAISERROR('Failed', 16, 1); END TRY BEGIN CATCH PRINT 'The module ''' + @Name + ''' does not compile.'; IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION; END CATCH FETCH NEXT FROM ObjectCursor INTO @Name; END CLOSE ObjectCursor; DEALLOCATE ObjectCursor;