0

I added a column to my table:

ALTER TABLE receivertip ADD COLUMN my_column BOOLEAN

then I added a check constraint:

ALTER TABLE receivertip ADD CONSTRAINT my_column_ck CHECK(my_column IN (0, 1))

but sqlite (I'm using DB Browser for Sqlite) gives me an error:

near "CONSTRAINT": syntax error: 

What am I doing wrong ?

1 Answers1

0

The ALTER TABLE command does not allow adding constraints. See the language documentation: https://sqlite.com/lang_altertable.html

To add the constraint, copy your tables contents into a new table, drop the old, then re-create the old table with the added constraint, then copy-back the data.

MrGumble
  • 5,631
  • 1
  • 18
  • 33
  • I don't know if it did at the time you wrote your answer, but nowadays you can add a check constraint at the same time as a column. – Donal Fellows Jun 11 '21 at 14:29