我想为文章创建一个表,它可以(但不需要)有一个到img-Source的链接。对于所有有链接的文章,还需要一个img-Type (应该是'png','svg‘或'jpg')。我不太明白如何才能使img-Type字段不为空,只针对img-Src字段不为空的值。
下面是我的代码(没有字段img-Type和img-Src的not null/null约束)
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'
);发布于 2020-01-28 17:24:12
添加一个新约束,用于检查两个值都为null还是两个值都不为null
check (imgSrc is not null and imgType is not null
or imgSrc is null and imgType is null)https://stackoverflow.com/questions/59945238
复制相似问题