Sql server 一个表中列之间的关系

Sql server 一个表中列之间的关系,sql-server,database,constraints,nullable,Sql Server,Database,Constraints,Nullable,我有以下表格: Create table Rent ( Id int not null, Id_car int not null, Date_rent date not null, Date_return date, Id_pleace_rent int not null, Id_pleace_return int ) 我想添加一个约束,即如果列“Date\u return”中的同一行为NULL,那么列“Id\u pleace\u return”也必须为NULL。我怎样才能做到这一点呢?现在这

我有以下表格:

Create table Rent
(
Id int not null,
Id_car int not null,
Date_rent date not null,
Date_return date,
Id_pleace_rent int not null,
Id_pleace_return int
)

我想添加一个约束,即如果列“Date\u return”中的同一行为NULL,那么列“Id\u pleace\u return”也必须为NULL。我怎样才能做到这一点呢?

现在这是SQL server,所以应该是以下几点:

ALTER TABLE Rent
ADD CONSTRAINT Nullability
CHECK (
(CASE WHEN Date_return IS NULL AND Id_pleace_return IS NOT NULL THEN 0 ELSE 1 END

)
GO

现在这是SQL server,因此应该是以下内容:

ALTER TABLE Rent
ADD CONSTRAINT Nullability
CHECK (
(CASE WHEN Date_return IS NULL AND Id_pleace_return IS NOT NULL THEN 0 ELSE 1 END

)
GO