SQL 整形
SQLクエリを整形。キーワードを大文字化して改行。
SQL 整形とは
SQL整形とは、SQLクエリのキーワードを大文字にし、句ごとに改行・インデントして読みやすくする処理です。
🔒 処理はすべてブラウザ内で完結し、データは送信されません。
このツールの前提
- 処理場所
- このページのブラウザ内(JavaScript / Canvas)
- アップロード
- なし — ファイルは端末の外に出ません
- オフライン
- ページを開いた後は通信不要
String literals are protected before anything moves
Every single-quoted literal is swapped for a placeholder, the text is reformatted, and the literals are restored afterwards. Without that step, a keyword inside a string — WHERE note = 'order by date' — would be treated as syntax and split across lines, changing the query's meaning.
The formatter then breaks on major clauses (SELECT, FROM, WHERE, GROUP BY, ORDER BY, JOIN) and indents their bodies. It does not parse the statement: it has no grammar, so it will happily format text that no database would execute.
Dialects it will misrepresent
Quoting differs per database: MySQL uses backticks, SQL Server brackets, PostgreSQL and the standard use double quotes for identifiers and single quotes for strings. PostgreSQL's dollar-quoted strings ($$ … $$) and MySQL's /*! */ executable comments are not recognised, so their contents may be reflowed.
That does not corrupt the query as sent to the database — the original text is unchanged apart from whitespace — but it does make the formatted version misleading to read. Verify against the original if the statement contains any of those constructs.
What formatting is for
Readability in review, and making a generated query legible. The output has no performance meaning: a database's planner ignores whitespace entirely, so a beautifully indented query and the same query on one line produce identical plans.
For correctness, formatting proves nothing. Run EXPLAIN on the real database, and use a schema-aware linter if you want to catch missing columns or type mismatches — neither is detectable from the text alone.
使い方
- 1.SQLを貼り付け
- 2.「整形する」をクリック
- 3.結果をコピー
他の方法との比較
同じ変換をする方法は 3 つあります。ブラウザ内(このページ)、サーバー側の変換サービス、デスクトップアプリ。差がつくのは速度ではなく、ファイルがどこへ行くかと、無料でどこまでできるかです。
| 観点 | このツール | サーバー側の変換サービス | デスクトップアプリ |
|---|---|---|---|
| ファイルの処理場所 | このページのブラウザ内 | ベンダーのサーバー(アップロード後) | 自分の PC(アプリをインストール) |
| アカウント | 不要 | 多くの場合必要(無料枠の制限解除に登録を求める) | 不要(ライセンス認証は必要な場合あり) |
| 無料で扱えるサイズ | サイズ制限なし(回数制限もなし) | 数ファイル/時間、または 5〜10MB 程度で課金 wall | ディスクとメモリ次第 |
| 料金 | 無料。Pro は月 $9(大きいファイルと AI 機能のみ) | サブスクが一般的。おおむね月 $7〜15(2026 年 11 月時点) | 買い切り、またはサブスク |
| オフライン | 一度開けば通信不要 | 不可 | 可 |
| 20MB を処理し始めるまで | 待ち時間なし(アップロードが無い) | アップロードが支配的(10Mbps 上りで約 16 秒) | アプリの起動のみ |
| 保証できないこと | 不正な入力は「修復」せず、パーサのエラー位置を返します | 同じ(変換の原理は変わらない) | 同じ。ただし書式の再現はより忠実な場合がある |
サーバー側のサービスが優れている点は明確にあります。巨大なファイル、チームでの共有、変換履歴の管理、スクリプトからの自動化。逆に「1 回だけ、手元のファイルを別形式にしたい」という今回の用途では、アップロードの待ち時間と登録の手間だけが増えます。
よくある質問
SQL整形とは?
キーワードの大文字化と改行でクエリを読みやすくします。
文字列リテラルは?
クォート内の文字列は保護してそのまま保持します。
この変換で失われるもの
フォーマッタは入力を構文木に解析し、一貫したインデントで出力します。入力が不正なら、黙って壊れたファイルを返すのではなく、パーサのエラー位置を表示します。壊れた JSON は「修復」されず、そのまま壊れたまま示されます。