SQL 格式化器

最后更新:

关于此工具

SQL 格式化工具用统一缩进、关键字大写、每子句一行让长 SELECT 真正可读。还提供 minify 模式去掉换行,方便嵌入到应用代码或环境变量中。任何看过别人把 50 行查询写成 1 行的开发者都会喜欢。

使用方法

  1. Paste the SQL query into the input panel.
  2. Click Format to render an indented, keyword-uppercased version on the right.
  3. Use Minify to collapse the formatted query into a single line for embedding.
  4. Copy the result into your IDE, ORM raw query, BI tool, or migration file.
  5. Iterate until the query reads naturally — formatting helps catch missing JOIN conditions and stray commas.

常见用例

  • Cleaning up a complex JOIN before pasting it into a code review.
  • Formatting an ORM-generated query you copied from a log for debugging.
  • Preparing a migration script for a Pull Request that follows team style.
  • Minifying a query for embedding inside an application config string.
  • Comparing two slightly different queries with a diff tool after formatting both.
  • Sharing a readable query in documentation or a Slack thread.

常见问题

Q. Does the formatter validate my SQL?

A. No — it formats syntax structure but does not verify that columns or tables exist or that the query runs. Use a database client or linter for validation.

Q. Will formatting work for non-standard SQL dialects?

A. Mostly. Common keywords across PostgreSQL, MySQL, SQLite, and MSSQL are recognised. Vendor-specific syntax (PIVOT, MERGE) may format with awkward indentation.

Q. Why does my formatter break a CTE in the wrong place?

A. CTEs (WITH clauses) and subqueries are tricky. If the result looks off, hand-tweak after formatting — it is still faster than starting from scratch.

Q. Should I commit formatted SQL to my repo?

A. Yes — consistent SQL formatting in migrations and stored procedures pays off in code review, just like JS/Python formatting.