views:

68

answers:

3

Experimenting with new features of T-SQL, I've run into a puzzle. Here is some new syntax supported by SQL 2008 and I'd expect it to work on databases set for compatibility mode 100 (i.e. 2008) and not work for compat mode 80 (i.e. 2000). Yet this works for a database set for SQL SERVER 2000 compatibility mode on a SQL 2008 instance of Standard edition:

use MDS    -- this db is compat mode 80
go
CREATE TABLE dbo.Employees
(
Name VARCHAR(50) NULL,
Email VARCHAR(50) NULL,
Salary money NULL
) 
INSERT INTO dbo.Employees(Name, Email, Salary)
VALUES('Scott', '[email protected]', 50000.00),
  ('Jisun', '[email protected]', 225000.00),
  ('Alice', '[email protected]', 75000.00),
  ('Sam', '[email protected]', 45000.00)

SELECT * FROM dbo.Employees  
drop table dbo.Employees
A: 

I don't see how this could work in compat mode 80. Try adding this line before you create your table:

sp_dbcmptlevel 'MDS'

Does it return 80?

Abe Miessler
Yes, it does. I run the script on database with "Compatibility level" set to "SQL Server 200(80) on MS SQL Server 2008 R2
vgv8
+2  A: 

I noticed this too, and found this statement on MSDN:

Sets certain database behaviors to be compatible with the specified version of SQL Server.

The compatibility mode affects "certain" behaviors, and not ALL behaviors. See the ALTER DATABASE documentation for details.

devio
+1  A: 

The compatibility mode setting is used to control certain relatively obscure (imho) aspects of databae engine behavior. It does not block or prevent the use of extensions to the T-SQL language from being used on databases migrated from prior versions--for example, a database backed up from SQL 2000 and restored on SQL 2008 will support CTEs and the new multi-value INSERT statements.

The actual details of what is controlled by the database compatibility mode are buried in several articles in Books Online; this is a good starting place for researching this.

Philip Kelley