Presume there are several older versions of SQL Server databases exist in your current SQL Server instance and you want to change all of those Databases Compatibility level to higher version at once. Below script might be helpfully you to achieve that goal. This can be set using SQL Server Management Studio but if you have lots of databases it might take very long time.
Here is a listing of the available compatibility levels.
Version | Compatibility Level | Oldest Available Level |
SQL 2014 | 120 | 100 |
SQL 2012 | 110 | 90 |
SQL 2008 | 100 | 80 |
SQL 2005 | 90 | 70 |
SQL 2000 | 80 | 70 |
SQL 7.0 | 70 | – |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
USE [master]; GO SET NOCOUNT ON DECLARE @SQL NVARCHAR(MAX); DECLARE @COMPATIBILITY_LEVEL INT; SET @COMPATIBILITY_LEVEL=110;----**SET appropriate database compatibility level** DECLARE #databases CURSOR FOR SELECT NAME FROM master..sysdatabases where dbid>4 DECLARE @database_name varchar(128) OPEN #databases FETCH #databases INTO @database_name WHILE @@FETCH_STATUS = 0 BEGIN SELECT @SQL = 'ALTER DATABASE ['+ @database_name+'] SET COMPATIBILITY_LEVEL = '+CAST(@COMPATIBILITY_LEVEL as VARCHAR(10))+''; EXEC(@SQL) FETCH #databases INTO @database_name END CLOSE #databases DEALLOCATE #databases |
Leave a Comment