Conditional SQLite check constraint?

后端 未结 3 1639
忘了有多久
忘了有多久 2020-12-29 03:12

I have a table defined by the following SQL:

CREATE TABLE test (
  id       integer PRIMARY KEY NOT NULL UNIQUE,
  status   text NOT NULL,
  enddate  date,
          


        
3条回答
  •  臣服心动
    2020-12-29 03:25

    CREATE TABLE test (
      id       integer PRIMARY KEY,
      status   text NOT NULL CHECK (status IN ('Current', 'Complete')),
      enddate  date NOT NULL
    );
    

    This will work in SQLite, with the CHECK constraint written inline. I changed double quotes to apostrophes so it can be used in PHP.

提交回复
热议问题