Alex Szabo
Alex Szabo

Reputation: 3266

SQL Server compatibility issue

I have a rather old and very long query written in the stone age of SQL Server 2000. As you may suspect this uses the old joins like c.address_id =* b.address_id

When I try to run it, an error message pops up that I have to set the compatibility level to 80 to enable this type of join. Which I have tried this way:

ALTER DATABASE SandBox
SET compatibility_level = 80

But it seems like that this is being ignored. The script is around 800 rows - so is there any way to run this query in MSSQL 2008 without rewriting it?

It would be required to run overnight twice a week, so for this time I won't care about the performance of the script, etc.

Any suggestions are welcome.

Upvotes: 0

Views: 112

Answers (2)

cupholdR
cupholdR

Reputation: 75

Not exactly sure on what did you try so far, but executing it within the current script will not necessarily work. If you still struggle with setting the compatibility level, try opening a new query window and run only that portion.

Upvotes: 1

granadaCoder
granadaCoder

Reputation: 27852

I would rewrite it.

Having said that, this worked for me.

ALTER DATABASE ScratchPadDB
SET compatibility_level = 80

Select @@Version /* Microsoft SQL Server 2008 R2 (RTM) - 10.50.1600.1 (Intel X86)   Apr  2 2010 15:53:02   Copyright (c) Microsoft Corporation  Developer Edition on Windows NT 6.1 <X64> (Build 7601: Service Pack 1) (WOW64) (Hypervisor)  */

/**/


IF EXISTS ( SELECT * FROM INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA = N'dbo' and TABLE_NAME = N'Employee' and TABLE_TYPE = N'BASE TABLE' ) 
BEGIN 
DROP TABLE [dbo].[Employee] 
END 
GO


IF EXISTS ( SELECT * FROM INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA = N'dbo' and TABLE_NAME = N'Department' and TABLE_TYPE = N'BASE TABLE' ) 
BEGIN 
DROP TABLE [dbo].[Department] 
END 
GO

/**/ 


CREATE TABLE [dbo].[Department](
    [DepartmentUUID] [uniqueidentifier] NOT NULL,
    [TheVersionProperty] [timestamp] NOT NULL,
    [DepartmentName] [nvarchar](80) NULL,
    [CreateDate] [datetime] NOT NULL
    )


ALTER TABLE dbo.[Department] ADD CONSTRAINT PK_Department PRIMARY KEY NONCLUSTERED ([DepartmentUUID]) 
GO

ALTER TABLE [dbo].[Department] ADD CONSTRAINT CK_DepartmentName_Unique UNIQUE ([DepartmentName]) 
GO


CREATE TABLE [dbo].[Employee] ( 

    [EmployeeUUID] [uniqueidentifier] NOT NULL,
    [ParentDepartmentUUID] [uniqueidentifier] NOT NULL,
    [TheVersionProperty] [timestamp] NOT NULL,
    [SSN] [nvarchar](11) NOT NULL,
    [LastName] [varchar](64) NOT NULL,
    [FirstName] [varchar](64) NOT NULL,
    [CreateDate] [datetime] NOT NULL,
    [HireDate] [datetime] NOT NULL
    )

GO

ALTER TABLE dbo.Employee ADD CONSTRAINT PK_Employee PRIMARY KEY NONCLUSTERED (EmployeeUUID) 
GO


ALTER TABLE [dbo].[Employee] ADD CONSTRAINT CK_SSN_Unique UNIQUE (SSN) 
GO

ALTER TABLE [dbo].[Employee] ADD CONSTRAINT FK_EmployeeToDepartment FOREIGN KEY (ParentDepartmentUUID) REFERENCES dbo.Department (DepartmentUUID) 
GO


Select * from
dbo.Department d, dbo.Employee e
Where
d.DepartmentUUID =* e.ParentDepartmentUUID

Upvotes: 1

Related Questions