Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

sqlite

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

like image 725
Menai Ala Eddine - Aladdin Avatar asked Dec 31 '25 18:12

Menai Ala Eddine - Aladdin


1 Answers

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.

like image 78
varro Avatar answered Jan 05 '26 05:01

varro



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!