0

I have a table which is like

CREATE TABLE MyTable(
    id INTEGER PRIMARY KEY,
    type CHAR(1)
);

Later im my code i try to add an constraint to it with

ALTER TABLE MyTable ADD myCheckConstraint CHECK (type IN ('A', 'B'));

It work fine but when i look at my table there is also a new column named myCheckConstraint, is it normal ? How to just add the constraint without new column ?

Xiidref
  • 1,456
  • 8
  • 20
  • 1
    Yes - because you told SQLite so! By doing `ALTER TABLE ... ADD ....` you're effectively **adding a column** - so yes, it's expected that you now see a new column in your table - you instructed SQLite to add a column. – marc_s Apr 12 '20 at 18:24
  • 1
    Also see: https://stackoverflow.com/questions/42969127/add-constraint-to-existing-sqlite-table?rq=1 - seems SQLite doesn't support adding a constraint directly to an existing table ..... – marc_s Apr 12 '20 at 18:25

0 Answers0