How to add unique constraint in already made table in sqlite ios?

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:

Alter table

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


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.

Tags:

Sqlite

Ios