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. All processing happens entirely in your browser - your files never leave your device. No uploads, no accounts, complete privacy.

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 and beautify SQL queries with syntax highlighting. Supports multiple dialects and customizable formatting options.

Paste a SQL query, however tangled, and get a neatly formatted version with proper indentation, keyword capitalization, and line breaks. Supports SELECT, INSERT, UPDATE, DELETE, CREATE TABLE, and complex joins across common SQL dialects.

Text processed locallyMore document & textJump to full guide

Related reading

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

Initializing in your browser…

You might also like

XML Formatter & Tools

Format, validate XML with XPath queries, interactive tree view, XML-to-JSON conversion, and multiple color themes

YAML Formatter & Converter

Format, validate, and convert between YAML and JSON formats. Live validation, syntax highlighting, and bidirectional conversion.

Code Minifier & Beautifier

Minify or beautify code in 7 languages: JavaScript, TypeScript, CSS, HTML, JSON, XML, SQL with compression visualization

SQL Formatter: a worked example

You inherited a 12-line query crammed onto one line and need it readable before you can safely change a JOIN.

Input

select id,name from users u join orders o on o.uid=u.id where o.total>100
SQL Formatter produces

Formatted

SELECT id, name
FROM users u
JOIN orders o ON o.uid = u.id
WHERE o.total > 100

Keywords are cased and clauses placed on their own lines with consistent indentation, so the JOIN condition and filter are obvious and a missing predicate would jump out. Formatting is local, which matters because real queries often contain table and column names you should not paste into an external service.

About the SQL Formatter

Paste a SQL query, however tangled, and get a neatly formatted version with proper indentation, keyword capitalization, and line breaks. Supports SELECT, INSERT, UPDATE, DELETE, CREATE TABLE, and complex joins across common SQL dialects.

How it works

The SQL Formatter is a regular-expression beautifier that runs entirely in your browser with no external SQL parsing library. When you click Format SQL, it first collapses all runs of whitespace to single spaces (sql.replace(/\s+/g, ' ')), then walks a fixed list of roughly ninety keywords (SELECT, FROM, WHERE, JOIN, GROUP/BY, HAVING, ORDER/BY, LIMIT, INSERT, INTO, VALUES, UPDATE, SET, DELETE, CREATE, TABLE, WITH, UNION, plus type names like VARCHAR, SERIAL, DECIMAL, TIMESTAMP and functions like COUNT, COALESCE, NULLIF and NOW) and rewrites each whole-word match to your chosen keyword case via a case-insensitive \b regex. It then inserts line breaks before every major clause, pushes each AND, OR, and ON onto its own indented line, and breaks on commas. Because it only recognizes the words in its built-in SQL_KEYWORDS list, identifiers, vendor-specific functions, or newer keywords outside that set are left untouched in whatever case you typed them.

Layout is controlled by three on-screen dropdowns whose values persist in the page URL (via useUrlStates) so a configured formatter can be shared as a link: keyword case (UPPERCASE, lowercase, Capitalize), indent width, and comma position. The indent dropdown offers '2 spaces,' '4 spaces,' and '1 tab,' but indentation is built with the JavaScript expression ' '.repeat(indentSize) where the '1 tab' option maps to indentSize=1, so all three options produce spaces and '1 tab' yields a single space rather than an actual tab character. Comma position can be set to 'After (item,)' (trailing) or 'Before (, item)' (leading). The formatter always normalizes the statement to end with a semicolon, appending one if your input lacks it. Subquery nesting is handled with a light touch: an opening parenthesis immediately followed by SELECT gets a newline and one level of indent, and a doubled closing parenthesis ')\s*)' is split onto separate lines, but there is no true bracket-depth tracking, so deeply nested queries may not indent perfectly.

Although the type SqlDialect (standard, mysql, postgresql, sqlite, mssql) and a default 'standard' value exist in the component's URL state, there is no dialect dropdown rendered in the interface and the dialect value is never read by either the formatting or the minifying logic, so output is identical regardless of dialect; the only visible settings are keyword case, indent, and comma position. Alongside formatting, a Minify button strips the query to a single line by collapsing whitespace and removing the spaces around commas, parentheses, and equals signs (=). The formatted output is shown with regex-based syntax highlighting that colors single-quoted strings green (text-green-400), numeric literals orange (text-orange-400), recognized keywords blue (text-blue-400), and -- line comments gray (text-gray-500), and you can copy it, download it as formatted.sql, or read the live stats panel showing original and formatted character counts, total line count, and the count of recognized keywords. Seven preset sample queries (simple, complex, subquery, cte, insert, update, create) are available as one-click loaders.

How to use

  1. 1Paste your SQL query into the editor
  2. 2Select the SQL dialect if needed (Standard, PostgreSQL, MySQL, etc.)
  3. 3View the formatted output with proper indentation
  4. 4Copy the result

Key features

  • Automatic keyword uppercasing (SELECT, FROM, WHERE, etc.)
  • Intelligent indentation for subqueries and joins
  • Support for multiple SQL dialects
  • Handles complex queries with CTEs, window functions, and nested subqueries
  • Minify option to compress queries into a single line

When to reach for this

  • Cleaning up generated SQL

    Format machine-generated or ORM-produced queries into readable SQL for debugging and review.

  • Code review preparation

    Standardize SQL formatting before committing to version control so diffs are meaningful and reviews are easier.

  • Documentation and knowledge sharing

    Format complex queries cleanly for inclusion in runbooks, wiki pages, or onboarding documents.

  • Learning SQL structure

    See how a complex query is structured by formatting it with clear indentation, useful for understanding unfamiliar queries.

Tips & best practices

  • If a subquery is not indenting correctly, check for missing parentheses, the formatter relies on balanced brackets to determine nesting depth.
  • Use the minify option when embedding SQL in application code where readability is less important than compactness.

Examples

  • Format a one-line query

    Paste SELECT id, name FROM users WHERE status = 'active' ORDER BY created_at DESC and click Format SQL to get each clause (SELECT, FROM, WHERE, ORDER BY) on its own line with the column list broken on commas and a trailing semicolon added.

  • Minify before embedding in code

    Click Minify to collapse a multi-line query to one line, removing spaces around commas, parentheses, and equals signs, handy when pasting SQL into a string literal in application code.

Frequently asked questions

Which SQL dialects are supported?

The formatter handles standard SQL and common dialects including PostgreSQL, MySQL, SQLite, and Microsoft SQL Server syntax.

Does formatting change query behavior?

No. Formatting only affects whitespace and capitalization. The query logic and results remain identical.

Can it handle stored procedures?

Basic procedural SQL (BEGIN/END blocks, IF statements) is supported, though very complex dialect-specific syntax may not format perfectly.

Related tools and how they differ

  • JSON Formatter & Validator: Formats, queries, diffs, and schema-validates JSON data; use it for API payloads and config objects rather than SQL statements.
  • XML Formatter & Tools: Formats and validates XML and converts it to JSON; use it for markup documents like RSS, SVG, or config XML, not query text.
  • YAML Formatter & Converter: Converts and validates YAML and JSON config with auto-fix for common YAML mistakes; use it for settings files, not database queries.

Further reading

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

Private by design

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