Last active
January 20, 2023 12:30
-
-
Save kdclaw3/60523b9da4f2e37103078c03554b7751 to your computer and use it in GitHub Desktop.
Sql Server View Refresh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
refresh sql server database views | |
*/ | |
declare @name varchar(max) = '' | |
declare viewCursor cursor | |
for | |
select distinct [name] | |
from [sysobjects] | |
where [type] = 'V'; | |
open viewCursor | |
fetch next from viewCursor into @name | |
while @@FETCH_STATUS = 0 | |
begin | |
print 'Refreshing --> ' + @name; | |
begin try | |
exec sp_refreshview @name; | |
end try | |
begin catch | |
print ' **ERROR Refreshing --> ' + @name; | |
print ' ' + ERROR_MESSAGE(); | |
end catch | |
fetch next from viewCursor into @name; | |
end | |
close viewCursor | |
deallocate viewCursor |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment