Hands-on task
SQLite: foreign key
The database /root/lib.db already has a lookup table authors(id INTEGER PRIMARY KEY, name TEXT) with authors (id = 1 and 2). Create a table books(id INTEGER PRIMARY KEY, author_id INTEGER) such that the author_id column is a foreign key referencing authors(id). The schema must guarantee: a book with an existing author can be inserted, but a book referencing a non-existent author cannot (when foreign key enforcement is enabled).
- foreign key
- references
- create table
- pragma foreign_keys
- data integrity