Służy on do sprawdzenia kompatybilności obiektów w bazie danych podczas zmiany compatibility level na wyższy (np. z 2000 do 2005).
if OBJECT_ID('tempdb..#t') is not null
drop table #t
create table #t
(
name sysname not null primary key
, [type] char(2) not null
, error bit not null default 0
, done bit not null default 0
)
insert into #t (name, [type], error, done)
select name, [type], 0, 0 from sys.objects WHERE TYPE IN ('P', 'FN', 'IF', 'TF', 'V') order by name
declare @name sysname
declare @type char(2)
declare @i int
set @i = 0
while exists (select * from #t where done = 0)
begin
set @i = @i + 1
select top 1
@type = type
, @name = name
from #t
where done = 0
BEGIN TRY
IF @type = 'V'
exec sp_refreshview @name
ELSE
exec sp_refreshsqlmodule @name
END TRY
BEGIN CATCH
if XACT_STATE() = -1 rollback tran
update #t set error = 1 where name = @name
END CATCH
update #t set done = 1 where name = @name
print ltrim(str(@i)) + ' - ' + @name
if @i > (select count(*) from #t)
break
end
Brak komentarzy:
Prześlij komentarz