Schema Diagram Lab
Original interactive lab for this course — built on the Reddit-style
users/postsschema from the SQL lesson, extended here with acommentstable for the exercise below.
Query-writing is only half of the "SQL & DB design" interview question — the other half is reading (or drawing) an entity-relationship diagram and reasoning about foreign keys. This lab is a small draggable canvas: cards represent tables, and you connect them the way you'd sketch a schema on a whiteboard.
Explore: the shipped schema
This is the exact two-table schema the SQL lesson queries against. Drag the cards around, or rewire the connection — nothing here is graded, it's just the same diagram rendered as a canvas instead of a markdown table.
Notice the wire attaches to the specific user_id row on each card, not just "somewhere on the box" — table cards connect field-to-field, the way an ER tool would.
Exercise: wire the extended schema, and spot the missing column
Reddit posts also have comments. Below are three tables — users, posts, and a new comments table — with one bug: comments is missing the foreign key back to users (right now it only knows which post it's under, not who wrote it). You'll need to:
- Add the missing field. Click the dashed
+ field namerow insidecomments, typeuser_id, give it the badgeFK, and press Enter (or click +). - Wire the foreign keys, field to field: drag from
posts.user_idtousers.user_id, fromcomments.post_idtoposts.post_id, and from thecomments.user_idyou just added tousers.user_id. Direction matters (drag from the table that has the FK to the table it references); which side of the card you start from doesn't.
Click Check once you think it's done — after two wrong checks, whatever's still missing is revealed.
comments ends up with two foreign keys — one to posts, one to users — which is exactly the kind of "wait, doesn't this table need another FK" detail interviewers probe for when they hand you a schema with a subtly missing column.