• Numerous issues with this script. A lot of extra logic. It can be streamlined.

    1. Why all the dynamic SQL?

    2. The names of the views should be obtained from information_schema.tables WHERE table_type = 'VIEW'.

    3. When refreshing a view, you should also include the owner (schema). If there is more than one schema in the database, an error will result when you're refreshing the view and are executing as another owner (e.g., "dbo").

    4. There is no need for dynamic SQL when executing sp_refreshview.

    5. If dynamic SQL is to be used, procedure sp_executesql should be used vs. EXECUTE.

    6. I don't see the need for a temp table. a LOCAL FAST_FORWARD cursor against information_schema will work.

    Simpler logic attached.


    [font="Arial Narrow"](PHB) I think we should build an SQL database. (Dilbert) What color do you want that database? (PHB) I think mauve has the most RAM.[/font]