How to Set Compatibility Level for SQL Server 2008 or 2005 Database

When selecting data or performing query on Microosft SQL Server 2008 or SQL Server 2005 database, the following error message or failure may be returned:

[Microsoft][ODBC SQL Server Driver][SQL Server][Msg 4147, Level 15, State 1, Line 4] The query uses non-ANSI outer join operators (”*=” or “=*”). To run this query without modification, please set the compatibility level for current database to 80, using the SET COMPATIBILITY_LEVEL option of ALTER DATABASE. It is strongly recommended to rewrite the query using ANSI outer join operators (LEFT OUTER JOIN, RIGHT OUTER JOIN). In the future versions
of SQL Server, non-ANSI join operators will not be supported even in backward-compatibility modes.


or,

Msg 4147, Level 15, State 1, Line 3
The query uses non-ANSI outer join operators (”*=” or “=*”). To run this query without modification, please set the compatibility level for current database to 80 or lower, using stored procedure sp_dbcmptlevel. It is strongly recommended to rewrite the query using ANSI outer join operators (LEFT OUTER JOIN, RIGHT OUTER JOIN). In the future versions of SQL Server, non-ANSI join operators will not be supported even in backward-compatibility modes.

The error happens because Microsoft has dropped support for and eliminated old-style *= and =* outer join operators.

In order to fix the SQL Server error above, DB administrator has to set the database compatibility level to 80, which equivalent with SQL Server 2000 as a temporary workaround. Of course, the best solution is to modify the SQL statements or queries code to remove the old-style join operators with current standard SQL join syntax.

For example, SQL query below is not valid:

SELECT o.name FROM sys.objects o, sys.views v WHERE o.object_id *= v.object_id;

And should be replaced with the following code:

SELECT o.name FROM sys.objects o LEFT JOIN sys.views v ON o.object_id = v.object_id;

Or the following abbreviated inner join statement:

SELECT o.name FROM sys.objects o, sys.views v WHERE o.object_id = v.object_id;

For administrator who can’t change the code, the easiest workaround is to revert the compatibility level of the database in order to provide the backward compatibility to old-style joins. sp_dbcmptlevel stored procedures (deprecated) or Transact-SQL can be used to set certain (partially, not all) database behaviors to be compatible with the earlier version of SQL Server. This MSDN article provides overview on what behaviors are changed on each compatibility level.

Version of SQL Server that can be reverted to can be one of the following:

60 = SQL Server 6.0
65 = SQL Server 6.5
70 = SQL Server 7.0
80 = SQL Server 2000
90 = SQL Server 2005
100 = SQL Server 2008

Note: Compatibility level 60, 65, and 70 no longer available in SQL Server 2008. And future version of SQL Server will support only two (2) prior version of backward compatibility. A database containing an indexed view cannot be changed to a compatibility level lower than 80. Do also take note that when a database is set to backward-compatibility mode, some of the new functionalities may be lost, such as SQL CLR support and SSMS diagrams for the database. Beside, the compatibility mode affects behaviors only for the specified database, not for the entire server.

Steps to Change and Set Compatibility Level of A Database in SQL Server

The following SQL commands can be issued in SQL Server Management Studio Query window. Remember to execute Go after each command.

  1. Optional: Set the database to single user access mode:

    ALTER DATABASE database_name SET SINGLE_USER;

  2. Set the database compatibility level to one of the earlier version stated above:

    Transact-SQL Method

    ALTER DATABASE database_name SET COMPATIBILITY_LEVEL = { 80 | 90 | 100 }

    For example,

    ALTER DATABASE my_db SET COMPATIBILITY_LEVEL = 80

    sp_dbcmptlevel Stored Procedure Method

    EXEC sp_dbcmptlevel database_name, compatibility_level value;

    For example,

    EXEC sp_dbcmptlevel my_db, 90;

  3. Optional: Put back the database in multiuser access mode:

    ALTER DATABASE database_name SET MULTI_USER;


2 Responses to “How to Set Compatibility Level for SQL Server 2008 or 2005 Database”

  1. Andrew
    November 4th, 2009 16:23
    2

    The only criticism I have with this is that you don’t remind the user to set it back to MULTI_USER mode, assuming that the database was in MULTI_USER mode to begin with of course.

    Otherwise, thanks, these commands are what I needed.

  2. Microsoft – SQL Server – Strategies for addressing the Issue of deprecated SQL « Daniel Adeniji’s Trail
    August 14th, 2009 03:17
    1

    [...] 7)      My Digital Life. How to Set Compatibility Level for SQL Server 2008 or 2005 Database.  http://www.mydigitallife.info/2009/05/17/how-to-set-compatibility-level-for-sql-server-2008-or-2005-... [...]

Leave a Reply

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Subscribe to comments feature has been disabled. To receive notification of latest comments posted, subscribe to My Digital Life Comments RSS feed or register to receive new comments in daily email digest.
Custom Search

New Articles

Incoming Search Terms for the Article

sql server compatibility level - sql compatibility level - sql 2008 compatibility mode - sql server 2008 compatibility mode - sql compatibility mode - compatibility level sql server - the option 100 for compatibility mode is not supported - sql compatibility mode 80 - sql server 2008 compatibility - The query uses non-ANSI outer join operators ("*=" or "=*"). To run this query without modification, please set the compatibility level for current database to 80 or lower, using stored procedure sp_dbcmptlevel. It is strongly recommended to rewrite the query using ANSI outer join operators (LEFT OUTER JOIN, RIGHT OUTER JOIN). In the future versions of SQL Server, non-ANSI join operators will not be supported even in backward-compatibility modes. - non ANSI-SQL standard syntax for outer joins - sql 2008 compatibility - sql server 2008 2005 compatibility mode - how to change compatibility mode in sql server 2008 - SET COMPATIBILITY_LEVEL - please set the compatibility level for current database to 80 or lower - change sql server compatibility level - database compatibility mode is set to 90 - sql server 2008 backward compatibility - running sql server 2008 2000 compatibility mode - "SQL compatibility mode" - sql 2008 backward - the query uses non-ansi outer join operators or . to run this query without modification - compatibility mode SQL Server - set compatibility_level 2008 - sql server compatibility - sql server 2005 compatibility level - sql compatability level - sql 2005 compatibility level - Compatibility mode SQL 2008 - non ansi joins in sql 2008 - sql server 2008 compatibility setting - sql server compatibility levels - ansi sql 2008 standard - SQL 6.5 COMPATIBLE disable - SQL SERVER SET COMPATIBILITY LEVEL - compatibility level - SET COMPATIBILITY_LEVEL = 100 IN SQL - set compatibility level - MS SQL Server documentation on how to set the compatibility level for a database - sql express 2008 set compatibility l - sql server script compatibility mode - sql 2008 non ansi join support - +'sql server 2008' +'windows server 2005' +'compatability' - database compatibility mode sql server 2005 - sql server 2008 compatibility modes - sql server 2005 90 days trail free download - sql server change compatibility level - how to set compatibility level to 90 in sql server - sp_dbcmptlevel vs set compatibility_level -