Six months ago I wrote article about SQL SERVER – 2005 Change Database Compatible Level – Backward Compatibility. Yesterday I received an email asking that one of my blog reader is not able to use the sp_dbcmptlevel command with error that database is in use. He has asked me to write about proper procedure of changing database compatibility which will always work.
First read my previous article SQL SERVER – 2005 Change Database Compatible Level – Backward Compatibility as it has explained many details about compatibility.
The best practice to change the compatibility level of database is in following three steps.
- Set the database to single user access mode by using ALTER DATABASE SET SINGLE_USER.
- Change the compatibility level of the database.
- Put the database in multiuser access mode by using ALTER DATABASE SET MULTI_USER.
Above three steps are translated in T-SQL in following three line script. Run this procedure in Query Editor.
ALTER DATABASE AdventureWorks
SET SINGLE_USER
GO
EXEC sp_dbcmptlevel AdventureWorks, 90;
GO
ALTER DATABASE AdventureWorks
SET MULTI_USER
GO
Reference : Pinal Dave (http://blog.SQLAuthority.com)
