Skip to content

Instantly share code, notes, and snippets.

@kdclaw3
Last active January 20, 2023 12:30
Show Gist options
  • Save kdclaw3/60523b9da4f2e37103078c03554b7751 to your computer and use it in GitHub Desktop.
Save kdclaw3/60523b9da4f2e37103078c03554b7751 to your computer and use it in GitHub Desktop.
Sql Server View Refresh
/*
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