SQL 中另一个属性也不为空时的属性不为空

Attribute that is not null when an other attribute is also not null in SQL

我想为文章创建一个 table,它可以(但不需要)有一个 link 到一个 img-Source。对于所有具有 link 的文章,还需要一个 img-Type(应该是 'png'、'svg' 或 'jpg')。我不太明白如何使 img-Type 字段不为 null 仅对于 img-Src 字段不为空的值。

这是我的代码(没有 null/null 字段 img-Type 和 img-Src 的约束)

create TABLE Article(
articleID varchar(15) primary key ,
articleDescription varchar (80) null ,
imgSrc varchar (20)  ,
imgType  char(3),
check imgType = 'png' or imgType = 'svg' or imgType = 'jpg'
);

添加一个新约束,您可以在其中检查两个值是否为空或两个值都不为空

check (imgSrc is not null and imgType is not null 
    or imgSrc is null and imgType is null)