SQL SERVER COMPATIBILITY_LEVEL değişikliği

DECLARE @Database VARCHAR(255)
DECLARE @Table VARCHAR(255)
DECLARE @cmd NVARCHAR(500)
DECLARE @cmptlevel INT
SET @cmptlevel = (SELECT max( cmptlevel) FROM master.dbo.sysdatabases)
--select @cmptlevel

DECLARE DatabaseCursor CURSOR FOR
SELECT name FROM master.dbo.sysdatabases
WHERE cmptlevel < @cmptlevel OPEN DatabaseCursor FETCH NEXT FROM DatabaseCursor INTO @Database WHILE @@FETCH_STATUS = 0 BEGIN SET @cmd = ' ALTER DATABASE ' + @Database +' SET COMPATIBILITY_LEVEL = ' + cast(@cmptlevel as nvarchar(10)) + '' -- create table cursor print (@cmd) exec (@cmd) FETCH NEXT FROM DatabaseCursor INTO @Database END CLOSE DatabaseCursor DEALLOCATE DatabaseCursor