Monu Tools

SQL 格式化

格式化并美化 SQL 查询,对子句换行并统一关键字大小写,或将其压缩为单行。

如何使用 SQL 格式化

  1. 01

    将你的 SQL 查询粘贴到输入框。

  2. 02

    选择格式化以美化它,或压缩以将其压成一行。

  3. 03

    选择关键字大小写,然后复制结果。

What the SQL formatter does

This is a SQL formatter that takes a cramped, single-line or inconsistently styled query and beautifies it: each major clause on its own line, columns and conditions indented, and keyword casing made consistent. It can also do the reverse and minify a query to one line.

Why readable SQL helps

Readable SQL is easier to review, debug and maintain. When SELECT, FROM, WHERE, JOIN and GROUP BY each start a new line and the keywords share one casing, the shape of the query, what it returns and how it filters, becomes obvious at a glance.

Formatting is also useful right before committing a query so diffs stay small and reviewers see meaningful changes rather than reflowed whitespace.

Options and dialects

You choose the keyword casing (for example uppercase keywords, which is the common convention) and whether to format or minify. The formatter is dialect-agnostic and handles the common ANSI SQL used by PostgreSQL, MySQL, SQLite and SQL Server.

Minify mode is handy for the opposite need: collapsing a formatted query back to a single line to embed in code or a config value.

It formats, it does not validate

The tool formats for readability rather than checking that your query is valid, so it will happily lay out a query with a typo in it. Treat clean output as a readability win, not a correctness check.

Runs in your browser

Everything runs in your browser, which matters because real queries often contain table names, column names and sometimes literal values that hint at your schema or data. None of that is uploaded.

常见问题

格式化工具有什么作用?

它将 SELECT、FROM、WHERE 和 JOIN 等主要子句各放一行,缩进列和条件,并统一关键字大小写以便阅读。

我的 SQL 会发送到服务器吗?

不会。格式化完全在你的浏览器中运行,因此你的查询永远不会离开你的设备。这使得它对涉及表名或列名的查询是安全的。

支持哪些 SQL 方言?

它与方言无关,处理 PostgreSQL、MySQL、SQLite 和 SQL Server 使用的常见 ANSI SQL。它为可读性而格式化,而非校验语法。

嵌入此工具

将此工具添加到你自己的网站。复制下方代码片段即可,它会自动保持最新。

<iframe src="https://monu.tools/embed/zh/sql-formatter" width="100%" height="640" style="border:1px solid #e5e5e5;border-radius:12px;max-width:680px" loading="lazy" title="Monu Tools"></iframe>

相关工具