While following the official guideline for using foreign keys on the SQLite homepage, I discovered that the outcome is not what I expected. After creating the the corresponding tables:
CREATE TABLE artist(
artistid INTEGER PRIMARY KEY,
artistname TEXT
);
CREATE TABLE track(
trackid INTEGER,
trackname TEXT,
trackartist INTEGER,
FOREIGN KEY(trackartist) REFERENCES artist(artistid)
);
…and then inserting the exact corresponding data as shown in the tutorial, running the following query:
INSERT INTO track VALUES(14, 'Mr. Bojangles', 3);
…is accepted when I run it, contrary to what the guideline says. I have seen this behavior in other (similar) SQL scripts that I have written, so this guideline description shows fairly well other confusions I have had. Am I missing something? Thanks.
Aucun commentaire:
Enregistrer un commentaire