Format SQL Queries
Turn a query copied from a log, an ORM or a colleague's one-liner into readable SQL with each clause on its own line. Pick your database's dialect so its syntax is understood.
- Free
- Runs in your browser
- 14 SQL dialects
- No sign-up
How It Works
Format SQL in three steps.
Pick the dialect
PostgreSQL, MySQL, SQL Server, BigQuery and others each have their own syntax.
Paste the query
One query or several separated by semicolons.
Copy the result
Formatted as you type, with your choice of keyword case and indent.
What does a SQL formatter change?
Only whitespace and, if you choose, the case of keywords. Each major clause (SELECT, FROM, JOIN, WHERE, GROUP BY, ORDER BY) starts on its own line, column lists and conditions are indented, and subqueries are nested one level deeper. The query means exactly the same thing afterwards; it is just readable in a code review, a ticket or your editor. Formatting uses the open-source sql-formatter library.
If a query uses syntax the chosen dialect does not know, such as T-SQL square brackets under Standard SQL, formatting stops with an error. Switch to the right dialect and try again.
14 dialects
Standard SQL, PostgreSQL, MySQL, MariaDB, SQLite, SQL Server, Oracle PL/SQL, BigQuery, Snowflake, Redshift, Spark, DuckDB, ClickHouse and Trino.
Keyword case
Upper-case keywords, lower-case, or leave them as typed.
Indent
2 spaces, 4 spaces or tabs.
Several statements
Statements separated by semicolons are formatted one after another with a blank line between them.
Convert PDF Files and File Formats
Find the perfect online tool to combine PDF files, compress documents, and handle your daily workflow effortlessly.
PDF Tools
All your PDF needs in one place
- Merge PDF
- Organize PDF
- Split PDF
- Compress PDF
- Convert to Word
- Convert to Image
Image Tools
Edit and optimize your images
- Resize Image
- Compress Image
- Convert Format
- Crop Image
- Add Watermark
- Remove Background
Word Tools
Work with Word documents
- Convert to PDF
- Merge Documents
- Split Documents
- Compress File
- Edit Text
- Add Watermark
Excel Tools
Process Excel spreadsheets
- Convert to PDF
- Convert to CSV
- Merge Sheets
- Split Sheets
- Compress File
- Clean Data
Why Use This SQL Formatter
Readable SQL without an IDE.
Dialect-aware
Understands each database's quoting, functions and operators.
Formats as you type
No button to press; the result follows your input.
Queries stay private
Table names and data in your query are formatted in your browser and never uploaded.
One-click copy
Paste straight back into your editor or ticket.
Frequently Asked Questions
Questions people ask about the SQL Formatter.
No. Only spaces, line breaks and, optionally, keyword case change. String values and identifiers are left exactly as written.
The one your database uses. Standard SQL works for simple queries, but dialect features such as PostgreSQL's :: casts, MySQL backticks or T-SQL square brackets need the matching dialect.
The query has syntax the chosen dialect does not recognise, or it is incomplete (an unclosed quote or bracket). The error names the position where formatting stopped.
No, it only formats. For a one-line version, most editors can join lines, or use Find and Replace with a regular expression to replace \s+ with a single space.
Related Text & Developer Tools
More small utilities that run in your browser.
JSON Formatter
Format, validate and minify JSON.
Regex Tester
Test a regular expression and see every match.
Find and Replace
Replace words or patterns in any text, with regex support.
Text Diff Checker
Compare two texts and see what changed, line by line.
CSV to Markdown Table
Turn CSV or spreadsheet cells into a Markdown table.