[{"data":1,"prerenderedAt":123},["ShallowReactive",2],{"term-f\u002Fforeign-key":3,"related-f\u002Fforeign-key":109},{"id":4,"title":5,"acronym":6,"body":7,"category":89,"description":90,"difficulty":91,"extension":92,"letter":93,"meta":94,"navigation":95,"path":96,"related":97,"seo":103,"sitemap":104,"stem":107,"subcategory":6,"__hash__":108},"terms\u002Fterms\u002Ff\u002Fforeign-key.md","Foreign Key",null,{"type":8,"value":9,"toc":83},"minimark",[10,15,19,23,26,30,72,76,79],[11,12,14],"h2",{"id":13},"eli5-the-vibe-check","ELI5 — The Vibe Check",[16,17,18],"p",{},"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. It is like saying 'this order belongs to that user over there'.",[11,20,22],{"id":21},"real-talk","Real Talk",[16,24,25],{},"A foreign key is a column (or group of columns) in one table that references the primary key of another table. It enforces referential integrity — you cannot insert a foreign key value that does not exist in the referenced table, and deletion rules (CASCADE, RESTRICT, SET NULL) control what happens when the referenced row is deleted.",[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","CREATE TABLE orders (\n  id SERIAL PRIMARY KEY,\n  user_id INT REFERENCES users(id) ON DELETE CASCADE,\n  total DECIMAL(10,2)\n);\n","sql","",[38,39,40,48,54,60,66],"code",{"__ignoreMap":36},[41,42,45],"span",{"class":43,"line":44},"line",1,[41,46,47],{},"CREATE TABLE orders (\n",[41,49,51],{"class":43,"line":50},2,[41,52,53],{},"  id SERIAL PRIMARY KEY,\n",[41,55,57],{"class":43,"line":56},3,[41,58,59],{},"  user_id INT REFERENCES users(id) ON DELETE CASCADE,\n",[41,61,63],{"class":43,"line":62},4,[41,64,65],{},"  total DECIMAL(10,2)\n",[41,67,69],{"class":43,"line":68},5,[41,70,71],{},");\n",[11,73,75],{"id":74},"when-youll-hear-this","When You'll Hear This",[16,77,78],{},"\"The user_id column is a foreign key referencing the users table.\" \u002F \"Foreign keys prevent orphaned records.\"",[80,81,82],"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":84},[85,86,87,88],{"id":13,"depth":50,"text":14},{"id":21,"depth":50,"text":22},{"id":28,"depth":50,"text":29},{"id":74,"depth":50,"text":75},"database","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.","beginner","md","f",{},true,"\u002Fterms\u002Ff\u002Fforeign-key",[98,99,100,101,102],"Primary Key","JOIN","Referential Integrity","One-to-Many","Junction Table",{"title":5,"description":90},{"changefreq":105,"priority":106},"weekly",0.7,"terms\u002Ff\u002Fforeign-key","PQ1pb5l8oxWR2OXDZlznky8ZQMbcmuV7_OuVEDnD1As",[110,114,117,120],{"title":99,"path":111,"acronym":6,"category":89,"difficulty":112,"description":113},"\u002Fterms\u002Fj\u002Fjoin","intermediate","JOIN combines rows from two tables based on a related column.",{"title":102,"path":115,"acronym":6,"category":89,"difficulty":112,"description":116},"\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":101,"path":118,"acronym":6,"category":89,"difficulty":91,"description":119},"\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":98,"path":121,"acronym":6,"category":89,"difficulty":91,"description":122},"\u002Fterms\u002Fp\u002Fprimary-key","A primary key is the unique ID that every row in a table must have. Like a social security number for your data — no two rows can have the same one.",1776518281986]