Embed / use foreign keys in SQLite?

How can I implement a foreign key in SQLite? I thought something like this:

CREATE TABLE job (_id INTEGER PRIMARY KEY AUTOINCREMENT, employer_id INTEGER, ...); CREATE TABLE employer(_id INTEGER, employer_name TEXT NOT NULL, ...); 

Where employer_id is the _id from the employer table. Will this work? Is there another quick, perhaps less error prone? Maybe with triggers?

+1
source share
2 answers

I may not understand the question, but if this is the limitation you want, just do the following:

 ALTER TABLE Job ADD FOREIGN KEY (employer_id) REFERENCES Employer(_id) ON DELETE NO ACTION ON UPDATE NO ACTION; 
+2
source

See SQLite (3.6.19) Foreign Key Support

(An earlier version of SQLite does not support FK force relationships.)

+2
source

Source: https://habr.com/ru/post/1491008/


All Articles