Update Database Compatibility Level
-- This statement updates all databases that have a compatibility level
-- of 90 (SQL Server 2005) to 100 (SQL Server 2008)
DECLARE @ID INT
DECLARE @COUNT INT
DECLARE @DB_NAME NVARCHAR(200)
DECLARE @SQL NVARCHAR(200)
SET @ID = 1
SET @COUNT = (SELECT MAX(DBID) FROM sys.sysdatabases WHERE cmptlevel <> 100)
WHILE @ID <= @COUNT
BEGIN
SET @DB_NAME = (SELECT name FROM sys.sysdatabases
WHERE cmptlevel = 90 AND dbid = @ID)
IF @DB_NAME IS NOT NULL
BEGIN
SET @SQL = 'ALTER DATABASE
[' + @DB_NAME + ']
SET COMPATIBILITY_LEVEL
= 100'
EXEC (@SQL)
END
SET @ID = @ID + 1
END
No comments:
Post a Comment