/sql

SQL Formatter and Beautifier

Format and beautify SQL queries with indentation and uppercased keywords, for several dialects. All local.

How it works

Paste an SQL query and get it neatly formatted with indentation, line breaks and uppercased keywords. Choose the dialect (standard SQL, PostgreSQL, MySQL, SQLite, T-SQL and more) for correct syntax handling. Everything is formatted locally in your browser, nothing is sent anywhere.

About this tool

The SQL formatter takes your SQL code, often a single long line from a log excerpt or copied out of an ORM, and makes it readable with indentation, line breaks and keywords in uppercase. Useful when you need to understand a query from a production log, share a query in a pull request, or produce nicer migration files. The tool supports the common dialects: PostgreSQL, MySQL, MariaDB, SQL Server (T-SQL), Oracle PL/SQL and SQLite. Everything runs in the browser, no queries are sent to a server, so you can safely format queries that contain production data or sensitive column names.

How to use it

  1. Paste the SQL code into the text area.
  2. Pick a dialect from the dropdown for the best handling of function names and reserved words.
  3. The formatted code appears immediately in the "pretty" panel.
  4. Click "Copy" or "Download" to use the result in your editor.

Examples

SELECT with JOIN
Inputselect u.id, u.name, o.total from users u left join orders o on o.user_id=u.id where u.active=true order by o.total desc
OutputSELECT u.id, u.name, o.total FROM users u LEFT JOIN orders o ON o.user_id = u.id WHERE u.active = TRUE ORDER BY o.total DESC
INSERT ... VALUES
Inputinsert into orders(user_id,total,created_at) values (1,299.50,now()),(2,150.00,now())
OutputINSERT INTO orders (user_id, total, created_at) VALUES (1, 299.50, NOW()), (2, 150.00, NOW())
Rows in the VALUES list are automatically broken to one per line for readability.

Common use cases

  • Clean up queries from a slow log before pasting into EXPLAIN ANALYZE.
  • Share readable queries in code review and pull requests.
  • Write migration files that are trivial to diff over time.
  • Understand SQL generated by ORMs like Sequelize, Prisma, TypeORM or Django.
  • Teach SQL to beginners by showing correct indentation automatically.

Frequently asked questions

Does the tool change the query’s behaviour?
No. Only whitespace and keyword casing change, no semantics are touched. Comments are preserved.
Can I minify instead?
Yes. Switch to "compact" mode in the toolbar; all line breaks and duplicate spaces are removed. Handy for stashing the query in a JSON or YAML file.
Is the query executed against a database?
Never. The tool only does text formatting. Nothing is sent to a server and no database is touched. Safe even with sensitive queries.
Can I keep keywords lowercase?
Yes, set "Keywords: lowercase" in settings. Some coding standards prefer lowercase (Postgres style) while others prefer uppercase (Oracle style). The tool supports both.

Technical background

The SQL standard (ISO/IEC 9075) defines a common core, but every database adds its own extensions: PostgreSQL has "::" type casts, "RETURNING" clauses and "ILIKE"; MySQL has "LIMIT ... OFFSET" and backtick-quoted identifiers; T-SQL has "TOP N", "MERGE" and bracketed identifiers [dbo].[table]; Oracle has PL/SQL, hierarchical queries with CONNECT BY and the "DUAL" table; SQLite has limited ALTER TABLE and flexible typing. The formatter uses a tokenizer that splits the code into keywords, identifiers, literals, comments and whitespace, and then a pretty printer that inserts line breaks and indentation based on grammar rules for each clause (SELECT, FROM, WHERE, GROUP BY, etc.). Reserved words are lifted to uppercase (or lowered, if configured) while user-defined identifiers (table and column names) are preserved as-is. Comments, both -- line comments and /* block */ ones, keep their relative position. For complex CTEs, window functions and PIVOTs, pick the right dialect for best formatting.