格式化和美化 SQL 查詢,加入子句換行和統一關鍵字大小寫,或將其壓縮為單行。
如何使用 SQL 格式化
將 SQL 查詢貼入輸入框。
選擇「格式化」美化查詢,或「壓縮」將其壓縮為單行。
選擇關鍵字大小寫格式,然後複製結果。
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.
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.
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.
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.
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 等主要子句各放一行,縮排欄位和條件,並統一關鍵字大小寫以提升可讀性。
不會。格式化完全在瀏覽器中進行,查詢永遠不會離開您的裝置,即使查詢中包含資料表或欄位名稱也很安全。
與方言無關,能處理 PostgreSQL、MySQL、SQLite 和 SQL Server 使用的常見 ANSI SQL,注重格式化可讀性而非語法驗證。
嵌入此工具
將此工具加入你自己的網站。複製下方的程式碼片段,它會自動保持最新。
<iframe src="https://monu.tools/embed/zh-Hant/sql-formatter" width="100%" height="640" style="border:1px solid #e5e5e5;border-radius:12px;max-width:680px" loading="lazy" title="Monu Tools"></iframe>相關工具