SQLite3 — NOT NULL 应用于多列

bra*_*ese 1 sqlite constraints

在定义 SQLite3 表时,NOT NULL可以将约束应用于单个列:

CREATE TABLE tablename (
    field1 INTEGER NOT NULL,
    field2 INTEGER
);
Run Code Online (Sandbox Code Playgroud)

有没有办法不将NOT NULL约束应用于单个列,而是应用于一组两列或更多列,以便这些列中至少有一个不能为空,而其他任何或所有列都可以为空?

jue*_*n d 5

尝试

CREATE TABLE tablename 
(
    field1 INTEGER NOT NULL,
    field2 INTEGER,
    field3 INTEGER,
    CHECK (field2 is not null or field3 is not null)
);
Run Code Online (Sandbox Code Playgroud)