Sql-server – Does the compatibility level for sql server work reliably for scripts

compatibility-levelsql server

We have some DB scripts that need to be migrated from SQL Server 2008 R2 back to 2005, often scripts created in SQL Server 2008 / 2008 R2 won't run on a SQL Server 2005 installation (which some customers still use).

So my question: from your experience/knowledge, is this really necessary, or does setting the compatibility level back to 90 on SQL Server 2008 (2008 R2) fix the issue of unnoticed breaking scripts in SQL Server 2005? MSDN says "compatibility level provides only partial backward compatibility with earlier versions of SQL Server ", so I'm unsure here.

Thanks…


I would like a concrete list of “features will pass compatibility level 90 but break on SQL Server 2005" or link. If the list is short list, we could convert that to an internal "don't do that!" list and save a lot of work.

Best Answer

No. The compatibility level only affects some features that exists in both versions. To give an example from ALTER DATABASE Compatibility Level:

Compatibility-level setting of 90 or lower: MERGE is not enforced as a reserved keyword. Compatibility-level setting of 100: MERGE is a fully reserved keyword. The MERGE statement is supported under both 100 and 90 compatibility levels.

As you can see, you can still write a script that uses MERGE, a post SQL Server 2008 only feature, and run it in 90 compatibility mode, and it will work. However, the script will break on SQL Server 2005. The comptability level 90 only affects the enforcement of the keyword (which affects parsing, in 100 mode a table named MERGE would have to be enquoted in brackets as [MERGE]), but not the execution.

There are many more features like this. So your only option is to run against the target SQL Server.