|
Posted by Erland Sommarskog on 03/30/06 10:22
(rod.weir@gmail.com) writes:
> Hello, I have the following code to iterate through each view in a SQL
> Server and call the "sp_refreshview" command against it. It works
> great until it finds a view that is damaged, or otherwise cannot be
> refreshed. Then the whole routine stops working.
>
> Can someone please help me re-write this code so that any views that
> fail the "sp_refreshview" command get skipped. I'm sure it's just a
> matter of putting some basic error trapping into the loop, but I've had
> a few goes at it and failed.
If you are on SQL 2005, lookup TRY-CATCH in Books Online.
If you are on SQL 2000, you could possibly do the linked-server trick:
http://www.sommarskog.se/error-handling-I.html#linked-servers.
I'm not into refreshing views myself, but I can't think of a way to
detect this condition before-hand.
--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
Navigation:
[Reply to this message]
|