[{"data":1,"prerenderedAt":116},["ShallowReactive",2],{"term-u\u002Funique-constraint":3,"related-u\u002Funique-constraint":102},{"id":4,"title":5,"acronym":6,"body":7,"category":83,"description":84,"difficulty":85,"extension":86,"letter":87,"meta":88,"navigation":89,"path":90,"related":91,"seo":96,"sitemap":97,"stem":100,"subcategory":6,"__hash__":101},"terms\u002Fterms\u002Fu\u002Funique-constraint.md","Unique Constraint",null,{"type":8,"value":9,"toc":77},"minimark",[10,15,19,23,26,30,66,70,73],[11,12,14],"h2",{"id":13},"eli5-the-vibe-check","ELI5 — The Vibe Check",[16,17,18],"p",{},"A unique constraint tells the database 'no two rows can have the same value in this column.' Perfect for email addresses — you do not want two users with the same email. The database will flat-out reject duplicate inserts.",[11,20,22],{"id":21},"real-talk","Real Talk",[16,24,25],{},"A UNIQUE constraint ensures that all values in a column (or combination of columns) are distinct across all rows in the table. Unlike a primary key, a column with a UNIQUE constraint can contain NULL values (in most databases). It automatically creates an index on the column.",[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 users (\n  id SERIAL PRIMARY KEY,\n  email TEXT UNIQUE NOT NULL\n);\n","sql","",[38,39,40,48,54,60],"code",{"__ignoreMap":36},[41,42,45],"span",{"class":43,"line":44},"line",1,[41,46,47],{},"CREATE TABLE users (\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],{},"  email TEXT UNIQUE NOT NULL\n",[41,61,63],{"class":43,"line":62},4,[41,64,65],{},");\n",[11,67,69],{"id":68},"when-youll-hear-this","When You'll Hear This",[16,71,72],{},"\"Put a unique constraint on the username column.\" \u002F \"The insert failed because of a unique constraint violation.\"",[74,75,76],"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":78},[79,80,81,82],{"id":13,"depth":50,"text":14},{"id":21,"depth":50,"text":22},{"id":28,"depth":50,"text":29},{"id":68,"depth":50,"text":69},"database","A unique constraint tells the database 'no two rows can have the same value in this column.","beginner","md","u",{},true,"\u002Fterms\u002Fu\u002Funique-constraint",[92,93,94,95],"Primary Key","Index","Not Null","Table",{"title":5,"description":84},{"changefreq":98,"priority":99},"weekly",0.7,"terms\u002Fu\u002Funique-constraint","fTNcAx0DupuFviDs9R9KZ_ux6rNTccNzsY8VTg_PxsM",[103,107,110,113],{"title":93,"path":104,"acronym":6,"category":83,"difficulty":105,"description":106},"\u002Fterms\u002Fi","intermediate","A database index is like the index in the back of a book. Without it, the database reads every single row to find what you want.",{"title":94,"path":108,"acronym":6,"category":83,"difficulty":85,"description":109},"\u002Fterms\u002Fn\u002Fnot-null","NOT NULL is how you tell the database 'this field MUST have a value — you cannot leave it blank.",{"title":92,"path":111,"acronym":6,"category":83,"difficulty":85,"description":112},"\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.",{"title":95,"path":114,"acronym":6,"category":83,"difficulty":85,"description":115},"\u002Fterms\u002Ft\u002Ftable","A database table is exactly like a spreadsheet tab. It has columns across the top (name, email, age) and rows going down (one per person).",1776518321106]