I have an existing table in Sqlite. How do I add a unique constraint to it?
You can't add a constraint to existing table in SQLite,(In SQL there is a option for do that). You need to re-create the table with necessary contraints.
There is only a few option available for alter table command in sqlite. Please check the image:
Also check Sqlite org reference.
However you can add unique index for your table to achieve the same effect. So you can use the following query to achieve that:
CREATE UNIQUE INDEX your_unique_index ON your_table(column_name);
In most cases, UNIQUE and PRIMARY KEY constraints are implemented by creating a unique index in the database.
Reference : SQLite Constraints
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With