[{"data":1,"prerenderedAt":133},["ShallowReactive",2],{"term-m\u002Fmany-to-many":3,"related-m\u002Fmany-to-many":115},{"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":109,"sitemap":110,"stem":113,"subcategory":6,"__hash__":114},"terms\u002Fterms\u002Fm\u002Fmany-to-many.md","Many-to-Many",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",{},"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. You cannot model this with just two tables — you need a third 'junction' table in between.",[11,20,22],{"id":21},"real-talk","Real Talk",[16,24,25],{},"A many-to-many relationship means that multiple records in Table A can relate to multiple records in Table B. Since relational databases cannot directly represent this, it requires a junction table (also called a join table or bridge table) that holds foreign keys referencing both tables.",[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","-- Students and Courses: many-to-many\nCREATE TABLE enrollments (\n  student_id INT REFERENCES students(id),\n  course_id INT REFERENCES courses(id),\n  PRIMARY KEY (student_id, course_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],{},"-- Students and Courses: many-to-many\n",[41,49,51],{"class":43,"line":50},2,[41,52,53],{},"CREATE TABLE enrollments (\n",[41,55,57],{"class":43,"line":56},3,[41,58,59],{},"  student_id INT REFERENCES students(id),\n",[41,61,63],{"class":43,"line":62},4,[41,64,65],{},"  course_id INT REFERENCES courses(id),\n",[41,67,69],{"class":43,"line":68},5,[41,70,71],{},"  PRIMARY KEY (student_id, course_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],{},"\"Tags and posts have a many-to-many relationship — one post has many tags, one tag belongs to many posts.\" \u002F \"Use a junction table to implement many-to-many.\"",[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","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.","intermediate","md","m",{},true,"\u002Fterms\u002Fm\u002Fmany-to-many",[104,105,106,107,108],"Junction Table","One-to-Many","One-to-One","Foreign Key","ERD",{"title":5,"description":96},{"changefreq":111,"priority":112},"weekly",0.7,"terms\u002Fm\u002Fmany-to-many","Suxtf5ZEp_mf00HfZucBxpkca0rCEom9TAzuSwnJEGY",[116,120,124,127,130],{"title":108,"path":117,"acronym":118,"category":95,"difficulty":97,"description":119},"\u002Fterms\u002Fe\u002Ferd","Entity Relationship Diagram","An ERD is a visual map of your database — boxes for tables, lines showing how they connect.",{"title":107,"path":121,"acronym":6,"category":95,"difficulty":122,"description":123},"\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":125,"acronym":6,"category":95,"difficulty":97,"description":126},"\u002Fterms\u002Fj\u002Fjunction-table","A junction table (also called a join table) is the middle table you create to represent a many-to-many relationship.",{"title":105,"path":128,"acronym":6,"category":95,"difficulty":122,"description":129},"\u002Fterms\u002Fo\u002Fone-to-many","One-to-Many means one row in Table A can relate to many rows in Table B. One user can have many orders. One post can have many comments.",{"title":106,"path":131,"acronym":6,"category":95,"difficulty":122,"description":132},"\u002Fterms\u002Fo\u002Fone-to-one","One-to-One is a relationship where one row in Table A corresponds to exactly one row in Table B. Like a user and their profile — one user, one profile.",1776518294339]