'How to add unique constraint to existing table in Sqlite?
I have an existing table in Sqlite. How do I add a unique constraint to it?
Solution 1:[1]
I am assuming you are using SQLiteManager from FireFox, please create the table again, normally it doesn't allow to change the constraints when you have already created a table.
NOTE - It can be done using code too, this is another way of doing it..
Edited See the image below

Solution 2:[2]
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.
EDIT
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
Solution 3:[3]
You can add constraint by creating unique index:
CREATE UNIQUE INDEX ux_friend_name ON friend(name);
where ux_friend_name is unique index name, friend(name) - table and its columns that will be affected by this constraint.
You can read more here.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Community |
| Solution 3 | mixel |
