Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
Loading…
Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
Loading…
Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
SQL / POSTGRESQL / Learn / LESSON 05
Many-to-many uses a junction table: book_tags (book_id, tag_id) with two foreign keys and usually a composite PRIMARY KEY. Create books, tags, and book_tags together from an empty database.
Small example:
CREATE TABLE books (id INTEGER PRIMARY KEY, title TEXT NOT NULL);
CREATE TABLE tags (id INTEGER PRIMARY KEY, label TEXT NOT NULL);
CREATE TABLE book_tags (
book_id INTEGER REFERENCES books(id),
tag_id INTEGER REFERENCES tags(id),
PRIMARY KEY (book_id, tag_id)
);The database starts empty. Grading checks the schema/data you create across variants.
Expected verify columns: table_name, book_id, tag_id · row order is checked
Expected final state (displayed data):
Loading…Many-to-many uses a junction table: book_tags (book_id, tag_id) with two foreign keys and usually a composite PRIMARY KEY. Create books, tags, and book_tags together from an empty database.
QUERY STANDBY
›