Organize a data library: 10 levels of normalization, indexes, constraints and transactions. A database design game for moving from arrays to tables.
Welcome, Data Librarian. Your job is to design the right database schema. Each level gives you a scenario, and you pick the correct columns for each table. Careful: some columns are distractors that don't belong.
A Foreign Key (FK) links two tables. In a one-to-many relationship, the FK always sits on the "many" side. Example: one author → many books, so penulis_id (author id) lives in the books table.
A many-to-many relation can't be represented directly in SQL. You need a junction table (a go-between) that stores a pair of FKs from both tables. A junction table can also hold extra data about the relation (a grade, say).
1NF (First Normal Form): every column must contain an atomic value, one value per cell. Storing "A, B, C" in one column breaks 1NF. The fix: a separate table with one row per item.
An index speeds up lookups, like the index of a book. Index the columns you use often in WHERE, ORDER BY, and JOIN. But don't index every column: each index slows down INSERT/UPDATE.
Composite Primary Key = a PK made of 2+ columns. Good for a junction table where the FK pair already guarantees uniqueness. Alternative: a surrogate id + UNIQUE(user_id, role_id), a bit more flexible but it costs an extra column.
And more, 20 levels in all.