[{"data":1,"prerenderedAt":129},["ShallowReactive",2],{"term-j\u002Fjunction-table":3,"related-j\u002Fjunction-table":114},{"id":4,"title":5,"acronym":6,"body":7,"category":95,"description":96,"difficulty":97,"extension":98,"letter":99,"meta":100,"navigation":101,"path":102,"related":103,"seo":108,"sitemap":109,"stem":112,"subcategory":6,"__hash__":113},"terms\u002Fterms\u002Fj\u002Fjunction-table.md","Junction Table",null,{"type":8,"value":9,"toc":89},"minimark",[10,15,19,23,26,30,78,82,85],[11,12,14],"h2",{"id":13},"eli5-the-vibe-check","ELI5 — The Vibe Check",[16,17,18],"p",{},"A junction table (also called a join table) is the middle table you create to represent a many-to-many relationship. It has two foreign keys — one pointing to each of the two related tables. The students-courses problem is solved by an enrollments table.",[11,20,22],{"id":21},"real-talk","Real Talk",[16,24,25],{},"A junction table (associative table, bridge table, or join table) resolves many-to-many relationships by creating a table with foreign keys to both related tables. Each row represents one association between the two entities. It can also store attributes of the relationship itself (e.g., enrollment date).",[11,27,29],{"id":28},"show-me-the-code","Show Me The Code",[31,32,37],"pre",{"className":33,"code":34,"language":35,"meta":36,"style":36},"language-sql shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","-- post_tags is a junction table\nCREATE TABLE post_tags (\n  post_id INT REFERENCES posts(id) ON DELETE CASCADE,\n  tag_id INT REFERENCES tags(id) ON DELETE CASCADE,\n  PRIMARY KEY (post_id, tag_id)\n);\n","sql","",[38,39,40,48,54,60,66,72],"code",{"__ignoreMap":36},[41,42,45],"span",{"class":43,"line":44},"line",1,[41,46,47],{},"-- post_tags is a junction table\n",[41,49,51],{"class":43,"line":50},2,[41,52,53],{},"CREATE TABLE post_tags (\n",[41,55,57],{"class":43,"line":56},3,[41,58,59],{},"  post_id INT REFERENCES posts(id) ON DELETE CASCADE,\n",[41,61,63],{"class":43,"line":62},4,[41,64,65],{},"  tag_id INT REFERENCES tags(id) ON DELETE CASCADE,\n",[41,67,69],{"class":43,"line":68},5,[41,70,71],{},"  PRIMARY KEY (post_id, tag_id)\n",[41,73,75],{"class":43,"line":74},6,[41,76,77],{},");\n",[11,79,81],{"id":80},"when-youll-hear-this","When You'll Hear This",[16,83,84],{},"\"Add a junction table to handle the many-to-many relationship between posts and tags.\" \u002F \"The junction table can also store metadata about the relationship.\"",[86,87,88],"style",{},"html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":36,"searchDepth":50,"depth":50,"links":90},[91,92,93,94],{"id":13,"depth":50,"text":14},{"id":21,"depth":50,"text":22},{"id":28,"depth":50,"text":29},{"id":80,"depth":50,"text":81},"database","A junction table (also called a join table) is the middle table you create to represent a many-to-many relationship.","intermediate","md","j",{},true,"\u002Fterms\u002Fj\u002Fjunction-table",[104,105,106,107],"Many-to-Many","Foreign Key","Pivot Table","ERD",{"title":5,"description":96},{"changefreq":110,"priority":111},"weekly",0.7,"terms\u002Fj\u002Fjunction-table","CinsZ9prrJMwxacfsf5_6pDztZ2j5tpPtEdJ5CyLMm4",[115,119,123,126],{"title":107,"path":116,"acronym":117,"category":95,"difficulty":97,"description":118},"\u002Fterms\u002Fe\u002Ferd","Entity Relationship Diagram","An ERD is a visual map of your database — boxes for tables, lines showing how they connect.",{"title":105,"path":120,"acronym":6,"category":95,"difficulty":121,"description":122},"\u002Fterms\u002Ff\u002Fforeign-key","beginner","A foreign key is how you link two tables together. If an 'orders' table has a 'user_id' column pointing to the 'users' table, that is a foreign key.",{"title":104,"path":124,"acronym":6,"category":95,"difficulty":97,"description":125},"\u002Fterms\u002Fm\u002Fmany-to-many","Many-to-Many means rows on both sides can relate to many rows on the other side. Students can enroll in many courses, and courses can have many students.",{"title":106,"path":127,"acronym":6,"category":95,"difficulty":97,"description":128},"\u002Fterms\u002Fp\u002Fpivot-table","Pivot Table means two different things. In Laravel\u002FPHP it is just another name for a junction table.",1776518290348]