Skip to main content
L
Loopaloo
Buy Us a Coffee
All ToolsImage ProcessingAudio ProcessingVideo ProcessingDocument & TextPDF ToolsCSV & Data AnalysisConverters & EncodersWeb ToolsMath & ScienceGames
Guides & BlogAboutContact
Buy Us a Coffee
L
Loopaloo

Free online tools for developers, designers, and content creators. Your files are processed in your browser and are never uploaded - no accounts required. A few network utilities (like What's My IP and Currency Converter) call public APIs to do their job and say so on their pages.

support@loopaloo.com

Tool Categories

  • Image Tools
  • Audio Tools
  • Video Tools
  • Document & Text
  • PDF Tools
  • CSV & Data
  • Converters
  • Web Tools
  • Math & Science
  • Games

Company

  • About Us
  • Contact
  • Blog
  • FAQ

Legal

  • Privacy Policy
  • Terms of Service
  • Disclaimer

Support

Buy Us a Coffee

© 2026 Loopaloo. All rights reserved. Built with privacy in mind.

Privacy|Terms|Disclaimer
  1. Home
  2. Document & Text
  3. SQL Formatter
Add to favorites

SQL Formatter

Format or minify SQL as you type for MySQL, PostgreSQL, SQLite or SQL Server, with keyword case, indent and comma options that never touch your strings.

Text processed locallyMore document & textJump to full guide
Related readingSQL Formatting and Best Practices: Writing Readable, Maintainable Queries10 min

Initializing in your browser…

You might also like

XML Formatter & Tools

Format, minify or convert XML to JSON as you type, with line-and-column error checks, a tree view and XPath queries that handle namespaces.

YAML Formatter & Converter

Format and validate YAML or convert between YAML and JSON as you type, keeping comments, anchors and exact numbers, with YAML 1.1 and 1.2 support.

Code Minifier & Beautifier

Minify or beautify JavaScript, TypeScript, CSS, HTML, JSON, XML and SQL as you type, without touching strings or licences, and see the bytes saved.

SQL Formatter: a worked example

A slow-query log shows a one-line report query, and you need to read it to see why it is slow.

Logged query (PostgreSQL)

select u.id, u.name, count(o.id) as orders from users u left join orders o on o.user_id = u.id where u.note <> 'select from the menu' and u.created_at >= '2024-01-01' group by u.id, u.name having count(o.id) > 2 order by orders desc
What SQL Formatter produces

Formatted, uppercase keywords, 2-space indent

SELECT u.id,
  u.name,
  count(o.id) AS orders
FROM users u
LEFT JOIN orders o
  ON o.user_id = u.id
WHERE u.note <> 'select from the menu'
  AND u.created_at >= '2024-01-01'
GROUP BY u.id, u.name
HAVING count(o.id) > 2
ORDER BY orders DESC

Each clause now starts on its own line, the join condition sits under its JOIN and every AND condition is indented, so it is easy to check which filters apply. The words select and from inside 'select from the menu' stay lowercase because they are part of a string value, and the line under the result reports 1 statement, 14 keywords and 2 string literals kept exactly. Only whitespace and keyword case changed, so the query returns the same rows.

About the SQL Formatter

Paste a SQL query and get it laid out clause by clause as you type, with keywords in the case you prefer and syntax colouring, or minify it to one line. String values, quoted names and comments are never changed, and five SQL dialects are understood.

How it works

SQL copied from an application log, an ORM debug message or a colleague's chat message usually arrives as one long line. Reading it, reviewing it or spotting a missing join condition is much easier when each clause starts on its own line and conditions are indented under it. This formatter does that instantly in your browser, for a single query or a whole script.

Formatting that cannot break your query. The formatter reads the SQL as tokens first, the same way a database does, so it knows what is a keyword, what is a string literal, what is a quoted identifier and what is a comment. That sounds obvious, but simpler formatters use search-and-replace and end up upper-casing words inside values ('select from the menu' becoming 'SELECT FROM the menu'), splitting a value at a comma, or breaking a UNION into two words. Here only real keywords change case, and everything inside quotes or comments is copied exactly, so the formatted query returns the same rows as the original.

Dialects. Databases disagree on details that decide where a string ends. MySQL treats a backslash inside a string as an escape and quotes names with backticks; SQL Server uses square brackets; PostgreSQL has dollar-quoted strings such as $$ ... $$ for function bodies; standard SQL and SQLite double a quote to escape it. Choose your dialect and those rules are applied, which matters when a value contains quotes, backslashes or something that looks like a comment.

Your style. Keywords can be UPPERCASE, lowercase or left as written. Indent with 2 or 4 spaces, put commas at the end of each line or at the start of the next (leading commas make it easy to comment out a column), and choose whether clauses are separated by a blank line. Select lists, joins with their ON conditions, WHERE conditions joined by AND or OR, GROUP BY, HAVING, ORDER BY and LIMIT each get a clear place, and CTEs, subqueries, INSERT, UPDATE and CREATE TABLE statements are handled too.

Minify and check. Minify mode does the opposite: it removes comments and collapses whitespace into a single line while keeping strings intact, which is handy for embedding a query in code or a configuration file. A line under the result counts statements, keywords, string literals, quoted names, comments and bind parameters, so you can see at a glance that nothing was lost. Your SQL never leaves your browser, which matters for queries that contain table names, customer data or credentials.

How to use

  1. 1Paste your SQL, open a .sql file, or pick one of the examples (simple, complex, subquery, CTE, insert, update, create).
  2. 2Choose the dialect your database uses, then the keyword case, indent, comma position and spacing between clauses.
  3. 3Read the formatted query on the right; it updates as you type.
  4. 4Switch to Minify for a single-line version without comments.
  5. 5Copy the result or download it as a .sql file.

Key features

  • Live formatting as you type or paste
  • Token-based processing: strings, quoted names and comments never altered
  • MySQL, PostgreSQL, SQLite, SQL Server and standard SQL rules
  • UPPERCASE, lowercase or as-written keywords
  • 2 or 4 space indentation, leading or trailing commas, optional blank lines between clauses
  • Handles joins, subqueries, CTEs, INSERT, UPDATE and CREATE TABLE
  • Minify to one line with comments removed
  • Syntax colouring of keywords, strings, numbers, comments and parameters
  • Counts of statements, keywords, literals, comments and parameters
  • Runs locally in your browser

When to reach for this

  • Reading queries from logs

    Turn a one-line query from an ORM log or slow-query log into readable SQL to understand what the application actually runs.

  • Code review and pull requests

    Format a migration or report query consistently before committing, so reviewers can see each condition and join clearly.

  • Sharing SQL with a team

    Tidy a query before pasting it into documentation, a ticket or a chat, with keyword case matching your team's style.

  • Embedding SQL in code

    Minify a formatted query into a single line for a string constant or configuration file without breaking its literals.

Tips & best practices

  • Format a query before debugging it; a missing join condition or misplaced OR is much easier to spot on its own line.
  • Use leading commas when you often comment columns in and out while exploring data.
  • Choose the right dialect when queries contain backslashes, backticks or $$ blocks.
  • Keep a minified copy for code and a formatted copy for documentation, generated from the same source.

Examples

  • A one-line report query

    A lowercase query joining users and orders, with a WHERE, GROUP BY, HAVING and ORDER BY, formats to eleven lines with keywords upper-cased, the join condition indented under LEFT JOIN and each AND condition on its own line.

  • A keyword inside a value

    In WHERE u.note <> 'select from the menu', the words select and from stay lowercase because they are inside a string literal, and the keyword count does not include them.

  • MySQL backslash escapes

    With the MySQL dialect, 'It\'s fine' is read as one string containing an apostrophe; under standard SQL the same text would end the string early, which is why the dialect matters.

Frequently asked questions

Will formatting change what my query does?

No. Only whitespace and the letter case of keywords change. String literals, quoted identifiers, numbers and comments are kept exactly, so the query returns the same results.

Which SQL dialect should I choose?

The one your database uses. The choice affects how strings and names are recognised: MySQL uses backticks and backslash escapes, SQL Server uses square brackets, PostgreSQL supports dollar-quoted strings, and standard SQL and SQLite double a quote to escape it. If you are unsure, Standard SQL works for most simple queries.

Should keywords be uppercase?

Uppercase keywords are the most common convention because they separate SQL syntax from table and column names at a glance. Some teams prefer lowercase for less visual noise. Choose As written to leave the case untouched.

Why put commas at the start of a line?

Leading commas line up in one column and let you comment out or add a column by touching a single line, which also keeps version-control diffs small. Trailing commas read more like normal prose. Both produce the same query.

Can it format several statements at once?

Yes. Paste a script with statements separated by semicolons; each statement is formatted and the count under the result tells you how many were found.

Is my SQL sent to a server?

No. Formatting runs entirely in your browser, so queries containing table names, data or credentials stay on your device. The share link stores only your formatting settings.

Related tools and how they differ

  • Code Minifier & Beautifier: Minifies or beautifies SQL alongside JavaScript, CSS, HTML, JSON and XML.
  • CSV to SQL: Generates CREATE TABLE and INSERT statements from a CSV file.
  • Code Syntax Highlighter: Exports highlighted SQL as HTML or an image for slides and documentation.

Further reading

  • SQL Formatting and Best Practices: Writing Readable, Maintainable Queries10 min read

Private by design

Your text is processed locally in the browser. Nothing you paste or open is transmitted or logged.