SQL Formatter
Paste raw SQL and get it back clean, indented, and syntax-highlighted.
Overview
The SQL Formatter takes any SQL statement — no matter how minified, inconsistently cased, or awkwardly spaced — and reformats it with consistent indentation, aligned clauses, and your preferred keyword casing. The formatted result updates in real time in the right panel as you type or paste SQL into the left panel.
No Execution, No Network
The formatter only reformats your SQL text. It does not execute the query, connect to a database, or send data anywhere. All processing happens in the browser.
Real-Time Formatting
The formatted output panel refreshes as you type. No need to click a Format button — changes appear instantly.
Keyword Casing
Choose UPPERCASE, lowercase, or Title Case for SQL keywords. The casing setting applies globally across the entire query.
Configurable Indent
Set indentation to 2 spaces, 4 spaces, or a hard tab. The indent applies to nested clauses, subqueries, and CTE blocks.
Comment Preservation
Inline (-- comment) and block (/* comment */) comments are preserved exactly as written and positioned above the nearest clause.
Supported Dialects
The formatter handles standard ANSI SQL and dialect-specific extensions for all major databases. Dialect-specific syntax is formatted around its surrounding clauses and preserved exactly.
| Dialect | Supported Extensions |
|---|---|
| PostgreSQL | ON CONFLICT DO UPDATE, RETURNING, JSONB operators, WITH RECURSIVE CTEs, window functions |
| MySQL / MariaDB | LIMIT x OFFSET y, ON DUPLICATE KEY UPDATE, backtick identifiers, STRAIGHT_JOIN |
| SQLite | PRAGMA statements, WITHOUT ROWID, UPSERT syntax |
| SQL Server (T-SQL) | TOP N, WITH (NOLOCK), OUTPUT clause, square-bracket identifiers, GO batches |
| ANSI SQL | All standard DML and DDL: SELECT, INSERT, UPDATE, DELETE, CREATE/ALTER/DROP TABLE, CTEs, subqueries, joins |
Dialect Auto-Detection
The formatter attempts to detect the dialect automatically from keywords in your SQL (e.g. TOP implies T-SQL, RETURNING implies PostgreSQL). You can override detection with the Dialect selector in the toolbar if needed.
Formatting Options
All options are available in the toolbar above the input panel and take effect immediately.
| Option | Values | Default | Effect |
|---|---|---|---|
| Indent Size | 2 spaces · 4 spaces · Tab | 2 spaces | Controls indentation of nested clauses and subqueries |
| Keyword Case | UPPER · lower · Title | UPPER | Applies uniform casing to all SQL reserved words |
| Comma Position | End of line · Start of line | End of line | Places commas at the end or beginning of each list item in SELECT and INSERT |
| Newline Before Keywords | On · Off | On | Places major clause keywords (WHERE, AND, JOIN, ORDER BY) on their own line |
| Compact Mode | On · Off | Off | Reduces blank lines between clauses for a denser output |
Keyboard Shortcuts
| Shortcut | Action |
|---|---|
Ctrl+Shift+F / Cmd+Shift+F | Force re-format the current input (useful after changing options) |
Ctrl+A / Cmd+A | Select all text in the active panel |
Ctrl+C / Cmd+C | Copy selected text in the active panel |
Ctrl+Shift+C / Cmd+Shift+C | Copy entire formatted output to clipboard (from anywhere) |
Ctrl+Delete | Clear the input panel |
Copy & Export
Formatted SQL can be copied or exported from the right panel toolbar.
- Copy — Copies the entire formatted output to the clipboard. The button turns green briefly to confirm the copy succeeded.
- Download .sql — Downloads the formatted SQL as a
.sqlfile. The filename isformatted-query.sqlby default; rename the file after downloading. - Share Link — Generates a shareable URL that encodes the current input SQL in the URL fragment. The recipient opens the link and sees the same SQL pre-loaded in the input panel.
Format Before Code Review
Run your SQL through the formatter before including it in a pull request or documentation. Consistent indentation and casing makes SQL reviews significantly faster and catches misplaced clauses that are invisible in minified code.
AI Assistant
Open the built-in AI Assistant from the tab on the right edge of the screen to get help with your SQL. The assistant sees the selected dialect, the current SQL text, and the linter's findings, so you can ask things like:
- "Explain the top linter issue and how to fix it"
- "How can I optimize this query for better performance?"
- "Walk me through what this SQL does step by step"
- "What would change if I ran this on MySQL instead of PostgreSQL?"
The assistant does not execute the query or see a real query plan — it reasons over the SQL text and the static linter findings shown on screen.
FAQ
CREATE PROCEDURE and CREATE FUNCTION wrappers are formatted correctly. The body of procedural language blocks (PL/pgSQL $$...$$, T-SQL BEGIN...END) is preserved as-is and not reformatted, since procedural code has its own conventions that differ from SQL.