Is it okay for the foreign key field to have a different name than the field it references in the other table? If yes , how can it refer to the other table ?
Yes it is ok. Read sqlite foreign key document. It gives similar example. As you can see, column names are not same, but foreign key added nonetheless.
CREATE TABLE artist(
artistid INTEGER PRIMARY KEY,
artistname TEXT
);
CREATE TABLE track(
trackid INTEGER,
trackname TEXT,
trackartist INTEGER,
FOREIGN KEY(trackartist) REFERENCES artist(artistid)
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With