A FOREIGN KEY declaration says that each subrow of values that appears under listed columns of the table that REFERENCES also appears under the listed columns of the referenced table. The referenced columns have to be UNIQUE NOT NULL or a PRIMARY KEY. The "parent" table is the referenced one.
Whenever that's the case, declare a FOREIGN KEY. Otherwise don't.
It happens that if you JOIN on the two column lists, the result will have exactly one row per referencing table row.
With your two tables there's no foreign key to declare.
If you add a table author_books
holding rows where "author AUTHOR_ID authored book BOOK_ID" then its author_id
values have to be in author
and its book_id
values have to be in books
. So declare two FOREIGN KEYs:
FOREIGN KEY (author_id) REFERENCES author (author_id)
FOREIGN KEY (book_id) REFERENCES books (book_id)
(If an author always wrote exactly one book then you could add book_id
to author
with a foreign key to books
. If a book always had exactly one author then you could add author_id
to books
with a foreign key from author
. But that's not the real situation with authors and books.)
Constraint declarations allow the DBMS to disallow erroneous changes that would make the database have a value that cannot be right. You don't need constraints to query a database. (Including UNIQUE NOT NULL, PRIMARY KEY or FOREIGN KEY.)