Ala Eddine Menai
Ala Eddine Menai

Reputation: 2870

SQLite :How can i add primary key to table using alter?

Im trying to alter my table "Materiel" for make a primary key.,but this instruction is not working.

ALTER TABLE "MATERIEL" ADD CONSTRAINT "MATERIEL_PK" PRIMARY KEY ("MATRICULE")

This is stack trace:

[00:22:39] Error while executing SQL query on database 'Data': near "CONSTRAINT": syntax error

Upvotes: 3

Views: 6819

Answers (1)

varro
varro

Reputation: 2482

That won't work as that syntax is not supported by SQLite3 (see https://sqlite.org/lang_altertable.html). To do this, you need to re-create the table to include the constraint.

Upvotes: 4

Related Questions