• Just in case anyone was looking for a post SS 2k version that avoids cursors (and dare I say more readable?) version.

    /*

    uspRefreshViews

    Date: 2012-03-13

    purpose: to refresh the schema bindings of the current db

    usage: exec dbo.uspRefreshViews

    comments:

    omitted error handling (everyone has their own-rolled way which is best) and single view refresh

    */

    create proc dbo.uspRefreshViews

    as

    begin

    set nocount on

    declare @views table

    (id int identity(1,1) not null,

    schemaName NVARCHAR(128),

    viewName nvarchar(128) not null

    );

    declare

    @maxID int,

    @id int = 0,

    @aViewName nvarchar(128) = '',

    @aSchemaViewName NVARCHAR(258)

    insert into @views

    select sch.name, vw.name

    FROM sys.viewsvw

    inner join sys.schemas sch on sch.schema_id = vw.schema_id

    select @maxID = coalesce(@@ROWCOUNT,0)

    while @id <> @maxID

    begin

    select top 1 @id = id, @aSchemaViewName = schemaName + '.' + viewName

    from @views

    where @id < id

    order by id asc

    print 'Refreshing '+@aSchemaViewName

    EXECUTE sp_refreshview @aSchemaViewName

    end

    end

    Kind regards

    Derek