[{"data":1,"prerenderedAt":654},["ShallowReactive",2],{"guide-sql-formatting-standards-comparison":3},{"id":4,"title":5,"body":6,"date":641,"description":642,"extension":643,"meta":644,"navigation":648,"path":649,"readingTime":650,"seo":651,"stem":652,"__hash__":653},"guides\u002Fguides\u002Fsql-formatting-standards-comparison.md","SQL Formatting Standards Compared: Which Style Guide Should You Follow?",{"type":7,"value":8,"toc":625},"minimark",[9,14,18,21,24,28,33,36,42,85,89,92,96,116,119,122,126,143,147,255,259,262,268,309,315,343,346,357,360,371,374,378,384,404,410,429,432,436,445,465,470,488,494,498,501,528,531,535,538,541,561,564,568,588,592,601,605,621],[10,11,13],"h2",{"id":12},"why-sql-formatting-standards-matter","Why SQL Formatting Standards Matter",[15,16,17],"p",{},"Unformatted SQL is hard to read, hard to review, and hard to debug. A consistent formatting standard solves all three problems. But which standard should your team adopt?",[15,19,20],{},"Several organizations and communities have published SQL style guides. They agree on the basics — keywords uppercase, clauses on new lines — but diverge on specifics like comma placement, alias naming, and join indentation.",[15,22,23],{},"This guide compares the most widely referenced standards so you can make an informed choice.",[10,25,27],{"id":26},"the-major-style-guides","The Major Style Guides",[29,30,32],"h3",{"id":31},"sql-style-guide-by-simon-holywell","SQL Style Guide by Simon Holywell",[15,34,35],{},"The most popular open-source SQL style guide. It emphasizes readability and consistency with clear, opinionated rules.",[15,37,38],{},[39,40,41],"strong",{},"Key rules:",[43,44,45,49,64,67,70],"ul",{},[46,47,48],"li",{},"Keywords in uppercase",[46,50,51,52,56,57,56,60,63],{},"Each clause (",[53,54,55],"code",{},"SELECT",", ",[53,58,59],{},"FROM",[53,61,62],{},"WHERE",") on a new line",[46,65,66],{},"Commas at the end of lines (trailing commas)",[46,68,69],{},"Indentation: 2 spaces",[46,71,72,73,76,77,80,81,84],{},"Table aliases: short, meaningful (",[53,74,75],{},"customers"," → ",[53,78,79],{},"c",", not ",[53,82,83],{},"t1",")",[29,86,88],{"id":87},"mozilla-sql-style-guide","Mozilla SQL Style Guide",[15,90,91],{},"Mozilla's internal guide prioritizes consistency across large codebases with many contributors.",[15,93,94],{},[39,95,41],{},[43,97,98,100,103,106,109],{},[46,99,48],{},[46,101,102],{},"Right-align keywords to the longest keyword in the statement",[46,104,105],{},"Commas at the start of lines (leading commas)",[46,107,108],{},"Indentation: 4 spaces",[46,110,111,112,115],{},"Explicit ",[53,113,114],{},"AS"," for column aliases",[15,117,118],{},"###triSquared SQL Style",[15,120,121],{},"A pragmatic guide focused on reducing merge conflicts and diff noise.",[15,123,124],{},[39,125,41],{},[43,127,128,131,134,140],{},[46,129,130],{},"Leading commas preferred (easier to comment out lines)",[46,132,133],{},"One column per line",[46,135,136,139],{},[53,137,138],{},"JOIN"," conditions on their own line",[46,141,142],{},"Subqueries indented by one level",[10,144,146],{"id":145},"key-differences-compared","Key Differences Compared",[148,149,150,169],"table",{},[151,152,153],"thead",{},[154,155,156,160,163,166],"tr",{},[157,158,159],"th",{},"Rule",[157,161,162],{},"Holywell",[157,164,165],{},"Mozilla",[157,167,168],{},"triSquared",[170,171,172,186,199,212,227,242],"tbody",{},[154,173,174,178,181,184],{},[175,176,177],"td",{},"Comma position",[175,179,180],{},"Trailing",[175,182,183],{},"Leading",[175,185,183],{},[154,187,188,191,194,197],{},[175,189,190],{},"Keyword alignment",[175,192,193],{},"Left",[175,195,196],{},"Right",[175,198,193],{},[154,200,201,204,207,210],{},[175,202,203],{},"Indent size",[175,205,206],{},"2 spaces",[175,208,209],{},"4 spaces",[175,211,209],{},[154,213,214,219,222,224],{},[175,215,216,218],{},[53,217,114],{}," for aliases",[175,220,221],{},"Required",[175,223,221],{},[175,225,226],{},"Optional",[154,228,229,232,237,240],{},[175,230,231],{},"Join indentation",[175,233,234,235],{},"Same level as ",[53,236,59],{},[175,238,239],{},"Indented",[175,241,239],{},[154,243,244,247,250,252],{},[175,245,246],{},"Subquery style",[175,248,249],{},"Indented block",[175,251,249],{},[175,253,254],{},"CTEs preferred",[10,256,258],{"id":257},"the-leading-vs-trailing-comma-debate","The Leading vs Trailing Comma Debate",[15,260,261],{},"This is the most controversial formatting choice in SQL.",[15,263,264,267],{},[39,265,266],{},"Trailing commas"," (Holywell style):",[269,270,275],"pre",{"className":271,"code":272,"language":273,"meta":274,"style":274},"language-sql shiki shiki-themes github-light github-dark","SELECT\n  first_name,\n  last_name,\n  email\nFROM users\n","sql","",[53,276,277,285,291,297,303],{"__ignoreMap":274},[278,279,282],"span",{"class":280,"line":281},"line",1,[278,283,284],{},"SELECT\n",[278,286,288],{"class":280,"line":287},2,[278,289,290],{},"  first_name,\n",[278,292,294],{"class":280,"line":293},3,[278,295,296],{},"  last_name,\n",[278,298,300],{"class":280,"line":299},4,[278,301,302],{},"  email\n",[278,304,306],{"class":280,"line":305},5,[278,307,308],{},"FROM users\n",[15,310,311,314],{},[39,312,313],{},"Leading commas"," (Mozilla \u002F triSquared style):",[269,316,318],{"className":271,"code":317,"language":273,"meta":274,"style":274},"SELECT\n  first_name\n  , last_name\n  , email\nFROM users\n",[53,319,320,324,329,334,339],{"__ignoreMap":274},[278,321,322],{"class":280,"line":281},[278,323,284],{},[278,325,326],{"class":280,"line":287},[278,327,328],{},"  first_name\n",[278,330,331],{"class":280,"line":293},[278,332,333],{},"  , last_name\n",[278,335,336],{"class":280,"line":299},[278,337,338],{},"  , email\n",[278,340,341],{"class":280,"line":305},[278,342,308],{},[15,344,345],{},"Arguments for leading commas:",[43,347,348,351,354],{},[46,349,350],{},"Easier to comment out individual lines without fixing commas",[46,352,353],{},"Diff-friendly — adding a column only changes one line",[46,355,356],{},"Missing comma errors are caught visually at the start of the line",[15,358,359],{},"Arguments for trailing commas:",[43,361,362,365,368],{},[46,363,364],{},"More natural reading flow (matches how lists work in English)",[46,366,367],{},"Consistent with most programming languages",[46,369,370],{},"Most SQL formatters default to trailing",[15,372,373],{},"Neither is objectively better. Pick one and enforce it consistently.",[10,375,377],{"id":376},"keyword-alignment","Keyword Alignment",[15,379,380,383],{},[39,381,382],{},"Left-aligned"," (common):",[269,385,387],{"className":271,"code":386,"language":273,"meta":274,"style":274},"SELECT first_name,\nFROM   users\nWHERE  status = 'active'\n",[53,388,389,394,399],{"__ignoreMap":274},[278,390,391],{"class":280,"line":281},[278,392,393],{},"SELECT first_name,\n",[278,395,396],{"class":280,"line":287},[278,397,398],{},"FROM   users\n",[278,400,401],{"class":280,"line":293},[278,402,403],{},"WHERE  status = 'active'\n",[15,405,406,409],{},[39,407,408],{},"Right-aligned"," (Mozilla):",[269,411,413],{"className":271,"code":412,"language":273,"meta":274,"style":274},"SELECT first_name,\n  FROM users\n WHERE status = 'active'\n",[53,414,415,419,424],{"__ignoreMap":274},[278,416,417],{"class":280,"line":281},[278,418,393],{},[278,420,421],{"class":280,"line":287},[278,422,423],{},"  FROM users\n",[278,425,426],{"class":280,"line":293},[278,427,428],{}," WHERE status = 'active'\n",[15,430,431],{},"Right alignment makes clauses visually distinctive, especially in long queries. Left alignment is simpler and works better with auto-formatters.",[10,433,435],{"id":434},"join-formatting","JOIN Formatting",[15,437,438,444],{},[39,439,440,441,443],{},"Joined at ",[53,442,59],{}," level"," (Holywell):",[269,446,448],{"className":271,"code":447,"language":273,"meta":274,"style":274},"SELECT u.first_name\nFROM users u\nJOIN orders o ON u.id = o.user_id\n",[53,449,450,455,460],{"__ignoreMap":274},[278,451,452],{"class":280,"line":281},[278,453,454],{},"SELECT u.first_name\n",[278,456,457],{"class":280,"line":287},[278,458,459],{},"FROM users u\n",[278,461,462],{"class":280,"line":293},[278,463,464],{},"JOIN orders o ON u.id = o.user_id\n",[15,466,467,409],{},[39,468,469],{},"Indented joins",[269,471,473],{"className":271,"code":472,"language":273,"meta":274,"style":274},"SELECT u.first_name\nFROM users u\n  JOIN orders o ON u.id = o.user_id\n",[53,474,475,479,483],{"__ignoreMap":274},[278,476,477],{"class":280,"line":281},[278,478,454],{},[278,480,481],{"class":280,"line":287},[278,482,459],{},[278,484,485],{"class":280,"line":293},[278,486,487],{},"  JOIN orders o ON u.id = o.user_id\n",[15,489,490,491,493],{},"Indentation becomes valuable with multiple joins, making the join chain visually distinct from the base ",[53,492,59],{}," clause.",[10,495,497],{"id":496},"choosing-a-standard-for-your-team","Choosing a Standard for Your Team",[15,499,500],{},"Consider these factors:",[502,503,504,510,516,522],"ol",{},[46,505,506,509],{},[39,507,508],{},"Team size",": Larger teams benefit from more prescriptive guides (Mozilla or Holywell)",[46,511,512,515],{},[39,513,514],{},"Existing codebase",": Adopt whatever is closest to your current convention to minimize churn",[46,517,518,521],{},[39,519,520],{},"Tooling",": Choose a guide that matches your auto-formatter's defaults — manual enforcement always fails",[46,523,524,527],{},[39,525,526],{},"Query complexity",": Teams writing complex analytics queries benefit from indentation-heavy styles (triSquared)",[15,529,530],{},"The best style guide is the one your team actually follows. A mediocre standard applied consistently beats a perfect standard applied inconsistently.",[10,532,534],{"id":533},"automating-formatting","Automating Formatting",[15,536,537],{},"Manual formatting does not scale. Use an auto-formatter and configure it to match your chosen standard.",[15,539,540],{},"Popular options:",[43,542,543,549,555],{},[46,544,545,548],{},[39,546,547],{},"sqlfmt"," — opinionated formatter inspired by Black (Python)",[46,550,551,554],{},[39,552,553],{},"SQLFormatter"," (VS Code extension) — configurable formatting rules",[46,556,557,560],{},[39,558,559],{},"pg_format"," — PostgreSQL-specific formatter",[15,562,563],{},"Run formatters in pre-commit hooks or CI pipelines to catch unformatted SQL before it reaches the main branch.",[10,565,567],{"id":566},"key-takeaways","Key Takeaways",[43,569,570,573,576,579,582,585],{},[46,571,572],{},"Three major SQL style guides dominate: Holywell (most popular), Mozilla (large-team focus), triSquared (diff-friendly)",[46,574,575],{},"The biggest分歧 is leading vs trailing commas — both have valid arguments",[46,577,578],{},"Right-aligned keywords improve readability for complex queries; left-aligned is simpler",[46,580,581],{},"Indented joins help distinguish join chains in multi-table queries",[46,583,584],{},"Auto-formatting is essential — manual enforcement breaks down at scale",[46,586,587],{},"Consistency matters more than which standard you pick",[10,589,591],{"id":590},"try-it-yourself","Try It Yourself",[15,593,594,595,600],{},"Format any SQL query instantly with our free ",[596,597,599],"a",{"href":598},"\u002Ftools\u002Fsql-formatter","SQL Formatter",". Paste your code, pick a style, and copy the cleaned-up result — no installation required.",[10,602,604],{"id":603},"related-guides","Related Guides",[43,606,607,614],{},[46,608,609,613],{},[596,610,612],{"href":611},"\u002Fguides\u002Fsql-formatting-guide","SQL Formatting Guide"," — core formatting rules and examples",[46,615,616,620],{},[596,617,619],{"href":618},"\u002Fguides\u002Fsql-best-practices","SQL Best Practices"," — writing efficient, maintainable queries",[622,623,624],"style",{},"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":274,"searchDepth":287,"depth":287,"links":626},[627,628,632,633,634,635,636,637,638,639,640],{"id":12,"depth":287,"text":13},{"id":26,"depth":287,"text":27,"children":629},[630,631],{"id":31,"depth":293,"text":32},{"id":87,"depth":293,"text":88},{"id":145,"depth":287,"text":146},{"id":257,"depth":287,"text":258},{"id":376,"depth":287,"text":377},{"id":434,"depth":287,"text":435},{"id":496,"depth":287,"text":497},{"id":533,"depth":287,"text":534},{"id":566,"depth":287,"text":567},{"id":590,"depth":287,"text":591},{"id":603,"depth":287,"text":604},"2026-05-28","Compare major SQL formatting standards and style guides. Learn the differences between naming conventions, indentation rules, and clause formatting across popular frameworks.","md",{"keywords":645,"immutable":648},[646,647],"sql-formatter","sql-formatting-standards-comparison",true,"\u002Fguides\u002Fsql-formatting-standards-comparison",7,{"title":5,"description":642},"guides\u002Fsql-formatting-standards-comparison","mO-HcKas6Gr_3wASYHjrIPlW46Aevln8yQtCWPEio7E",1780401337137]