我需要为我的一个 SQL 表创建一个唯一约束,它还将检查两个 case 语句。这在 Oracle 中运行良好。但我无法让它在 SQL Server 2008 中运行。我将这两个查询都放在这里。
ORACLE(工作正常):
CREATE UNIQUE INDEX UK2_TR_ASSESSMENTEMPLOYEE ON TR_ASSESSMENTEMPLOYEE
(CASE WHEN ("EMPLOYEEID" IS NOT NULL AND "SCHEDULE" IS NULL) THEN NULL
ELSE "EMPLOYEEID" END , CASE WHEN "SCHEDULE" IS NULL THEN NULL
ELSE "SCHEDULE" END )
SQL 服务器:
Alter table TR_ASSESSMENTEMPLOYEE
Add Constraint UK2_TR_ASSESSMENTEMPLOYEE Unique
(
CASE WHEN EMPLOYEEID Is Not NULL AND SCHEDULE IS NULL THEN NULL ELSE EMPLOYEEID,
CASE WHEN SCHEDULE IS NULL THEN NULL ELSE SCHEDULE
)
请救救我。提前致谢。