SQL Server All View Refresh

  • yusufkahveci

    SSC-Addicted

    Points: 466

    Comments posted to this topic are about the item SQL Server All View Refresh

    SQL Server Consultant
    yusufkahveci@sqlturkiye.com
    www.sqlturkiye.com

  • Jeff Moden

    SSC Guru

    Points: 997169

    So, what happens when the view is in a schema other than the default schema of the user using the script? 😉

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.
    "Change is inevitable... change for the better is not".
    "Dear Lord... I'm a DBA so please give me patience because, if you give me strength, I'm going to need bail money too!"

    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • SQLOzzie

    Ten Centuries

    Points: 1373

    How about this

    DECLARE
     @sqlTrexec NVARCHAR(MAX)='';

    SELECT @sqlTrexec = @sqlTrexec + '
    EXECUTE sp_refreshview N''' + QUOTENAME( SS.Name ) + '.' + QUOTENAME( SO.Name ) + ''';'
    FROM sys.objects AS SO
    INNER JOIN sys.schemas AS SS ON SO.SCHEMA_ID = SS.SCHEMA_ID
    WHERE SO.TYPE='V'
    ORDER BY SS.Name, SO.Name;

    EXECUTE (@sqlTrexec);

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply