SQL Formatter
Format and beautify SQL queries online for MySQL, PostgreSQL, SQLite, SQL Server and more, with keyword casing and indentation options. Runs in your browser.
Runs in your browser · Nothing uploadedFree · No sign-up
Something not working, or missing a feature? Send feedback
About the SQL Formatter
Long SQL queries are much easier to debug when each clause starts on its own line. The SQL Formatter indents queries for the dialect you use and can upper- or lower-case keywords.
Everything runs in your browser, so your input is never uploaded to a server.
How to use the SQL Formatter
- Paste one or more SQL statements.
- Select your dialect (MySQL, PostgreSQL, SQLite, SQL Server and others) and keyword casing.
- Copy or download the formatted SQL.
Example
Input
select u.id, u.email, count(o.id) as orders from users u left join orders o on o.user_id = u.id where u.active = 1 group by u.id, u.email order by orders desc limit 10
Result
SELECT u.id, u.email, count(o.id) AS orders FROM users u LEFT JOIN orders o ON o.user_id = u.id WHERE u.active = 1 GROUP BY u.id, u.email ORDER BY orders DESC LIMIT 10
Dialect MySQL, keywords in UPPERCASE, 2-space indentation. Function names such as count keep their original case.
Common mistakes
- Wrong dialect. Backtick identifiers (MySQL), square brackets (SQL Server) and :: casts (PostgreSQL) only parse in their own dialect. Pick yours before formatting.
- Template placeholders. Placeholders such as ${table} from application code are not SQL. Replace them with sample values or ? parameters first.
- Formatting does not check tables. A nicely formatted query can still reference a column that does not exist. Run it against your database to validate it.
Works well with the SQL Formatter
- SQL Minifier: collapse a query to one line for logs or code.
- JSON to SQL Insert: generate INSERT statements from JSON records.
- Text & Code Diff: compare two versions of a migration or query.
Frequently asked questions
Why choose a dialect?
Dialects differ in syntax such as quoting, operators and functions. Choosing the right one makes the formatter parse those correctly.
Does it validate my query?
It needs to tokenise the SQL, so badly broken queries are reported, but it does not check table or column names against a database.
Can it format several statements at once?
Yes. Separate statements with semicolons and each one is formatted in turn.
Does it change what my query does?
No. Only whitespace, line breaks and keyword case change; identifiers, values and the order of clauses are kept.
Guides and tutorials
Related tools
JSON Formatter
Format and beautify JSON with configurable indentation and optional key sorting. Errors are reported with exact line and column.
HTML Formatter
Format and beautify messy or minified HTML into clean, indented markup with Prettier, including embedded CSS and JavaScript. Runs locally in your browser.
CSS Formatter
Format and beautify CSS, SCSS and Less online with Prettier. Turn minified or messy stylesheets into readable, consistently indented code in your browser.
JavaScript Formatter
Format and beautify JavaScript and JSX online with Prettier. Choose indentation, quotes, semicolons and line width; your code is formatted in your browser.
TypeScript Formatter
Format and beautify TypeScript and TSX online with Prettier, including types, generics and decorators. Choose indentation, quotes and semicolons.
PHP Formatter
Format PHP code online with Prettier for PHP (@prettier/plugin-php): PSR-12 braces, spacing and 4-space indentation. No install, and nothing is uploaded.