简体   繁体   English

SQL Server兼容性问题

[英]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 我有一个相当老而且很长的查询,写在SQL Server 2000的石器时代。您可能会怀疑它使用了像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. 当我尝试运行它时,弹出错误消息,我必须将兼容性级别设置为80才能启用这种类型的联接。 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? 该脚本大约有800行-那么有什么方法可以在MSSQL 2008中运行该查询而无需重写它?

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. 欢迎任何建议。

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

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. 如果仍然难以设置兼容性级别,请尝试打开一个新的查询窗口并仅运行该部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM