Understanding COMPATIBILITY_LEVEL in SQL Server

两盒软妹~` 提交于 2019-11-26 23:28:20

问题


I understood that setting a database to a COMPATIBILITY_LEVEL prior to your native one prevented features from being used. However this doesn't seem to be the case. Witness the following SQL script:

CREATE DATABASE Foo
GO
USE Foo
GO
ALTER DATABASE Foo SET COMPATIBILITY_LEVEL = 80
GO

CREATE TABLE Bar
(
    Id UNIQUEIDENTIFIER NOT NULL,
    TestNvcMax NVARCHAR (MAX) NOT NULL, -- Arrived in SQL 2005
    TestDateTime2 DATETIME2 (7) NOT NULL -- Arrived in SQL 2008
)
GO

But this table creates perfectly - any ideas? I would have thought some kind of an error message or warning would have been appropriate


回答1:


Here you can read about the differences between compatibility level 80, 90 and 100. ALTER DATABASE Compatibility Level

Apparently new data types is not affected. I think that compatibility level is there to make SQL Server "behave" like the older version, not prevent you from doing new fancy stuff.




回答2:


BOL says:

Compatibility level provides only partial backward compatibility with earlier versions of SQL Server.

Also:

New functionality might work under older compatibility levels, but SET options might require adjustments.

I believe that is your case.




回答3:


I understand this is an old post, but for anyone else who ends up here as I did, more information is always helpful.

It could also be that the new compatibility did not take effect before running the create table statement.

"The new compatibility setting for a database takes effect when a USE Database is issued or a new login is processed with that database as the default database." (https://msdn.microsoft.com/en-us/library/bb510680.aspx)



来源:https://stackoverflow.com/questions/5624262/understanding-compatibility-level-in-sql-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!