企评社

Interface labels are shown in English. Company reviews, forum posts and tool descriptions are currently available in Chinese only.

SQL formatter

A statement or a whole script beautified in one click · 18 database dialects · keyword case and indentation configurable

全部在浏览器本地处理,SQL 与表名不上传、刷新即清空

格式化选项

输入 SQL

格式化结果

语句数 0
行数 0
字符数 0
耗时 0 ms

这个工具做什么、不做什么

只调整排版,不改语义。格式化只改空白、换行与关键字大小写:字符串字面量与注释里的内容一个字符都不动,不重命名标识符、不增删括号、不合并或拆分语句。因此格式化后的 SQL 与原 SQL 的语义一致(可用「去掉多余空白」再对比验证)。

不会修复语法错误。SQL 本身写错时(少了右括号、引号没闭合、关键字拼错),格式化会直接失败并给出「第几行第几列附近」的位置,而不是猜你的意思去补全。报错信息来自 sql-formatter 的解析器,本页把它整理成中文位置提示。

「去掉多余空白」不是压缩器。它把字符串与注释之外的连续空白压成一个空格(可选移除注释),不缩短标识符、不去括号、不做任何语法级压缩。字符串里的空格、注释里的换行都原样保留;勾选「移除注释」才会删除注释。

方言影响关键字识别与引号/注释规则。本页基于 sql-formatter 15.4.11,可选 18 种方言(另有 transactsql 的别名 tsql 未单列)。选错一般不会报错,但排版可能与预期不同(例如把 PostgreSQL 的 :: 类型转换当成普通符号);拿不准就用「标准 SQL」。

FAQ

Will formatting break my SQL?

No syntax-level rewriting. Formatting only adjusts whitespace, line breaks and keyword case - it never renames identifiers, never adds or drops parentheses, never touches literal contents, and not a single space inside strings or comments moves. The flip side: it will not repair syntax errors either - when the SQL itself is wrong (a missing closing parenthesis, an unclosed quote) it fails outright with the line and column position instead of guessing what you meant and completing it for you.

Which database dialects are supported? What if I pick the wrong one?

Tested on sql-formatter 15.4.11: 18 usable dialects plus a tsql alias for transactsql - standard SQL, MySQL, MariaDB, TiDB, SingleStore, PostgreSQL, Amazon Redshift, SQLite, SQL Server (T-SQL), Oracle PL/SQL, BigQuery, Snowflake, Spark SQL, Hive, Trino / Presto, IBM Db2, Db2 for i, Couchbase N1QL. The dialect decides keyword recognition, quoting and comment rules; picking the wrong one usually does not error but formats differently from what you expect (a PostgreSQL double-colon cast read as plain operators, say). When unsure, choose standard SQL.

Is strip-extra-whitespace a minifier?

No. It does exactly one thing: collapse runs of whitespace (spaces, newlines, tabs) outside string literals and comments into a single space, with removing comments optional. It does not shorten identifiers, does not drop parentheses, performs no syntax-level compression - so the size saving is small; treat it as a typographic move to squash one SQL snippet onto one line quickly, not an SQL minifier or obfuscator. Multiple spaces inside strings survive; comments stay by default (even the newlines inside block comments) and only vanish if you tick remove comments.

Is my SQL uploaded? Any size limit?

Nothing is uploaded. Lexing, formatting and whitespace stripping all run in your browser - sql-formatter is a self-hosted script, no CDN - so your SQL and table names never leave the machine; reloading clears it and the page issues no submit request at all. The cap is 200,000 characters per run; past 1,000 lines the page warns it may take a while - measured, ten-thousand-line scripts typically finish within one or two seconds.

Related tools