SQL Formatter

Beautify or minify SQL queries instantly in your browser. Supports keyword casing (UPPER/lower), custom indentation, comments, named parameters, and all major SQL dialects.

sql formatter beautify minify query mysql postgresql sqlite
Free Client-Side Private
🔒 This tool runs entirely in your browser — your files are never uploaded to any server.

Beautify or minify SQL queries instantly in your browser — supports keyword casing, custom indentation, and handles SELECT, INSERT, UPDATE, CREATE, and more.

How to Use

  1. Paste your SQL query into the input box or click Load file to upload a .sql file
  2. Choose Beautify to format the SQL with indentation and newlines, or Minify to compress it onto one line
  3. Select an indent style (2 spaces, 4 spaces, or Tab) and keyword casing (UPPERCASE, lowercase, or keep original)
  4. Click Beautify SQL (or Minify SQL)
  5. Copy the result or download it as a .sql file

Use Ctrl + Enter inside the input box to run without clicking the button.

Supported Statements

Category Statements
Query SELECT, FROM, WHERE, JOIN, ORDER BY, GROUP BY, HAVING, LIMIT
Write INSERT INTO, VALUES, UPDATE, SET, DELETE FROM
Schema CREATE TABLE, ALTER TABLE, DROP TABLE, CREATE INDEX, CREATE VIEW
Transaction BEGIN, COMMIT, ROLLBACK
Other UNION, WITH (CTE), CASE, EXPLAIN, TRUNCATE

Beautify vs Minify

Beautify adds consistent indentation and line breaks to improve readability. Each top-level clause (SELECT, FROM, WHERE, etc.) starts on a new line with controlled indentation inside sub-expressions. Comments are preserved and placed on their own lines.

Minify strips all comments and redundant whitespace to produce the shortest possible single-line output, useful for embedding queries in code or comparing diffs.

Tips

  • Use the Keyword selector to enforce UPPERCASE SQL keywords regardless of how they were originally written
  • You can format multiple statements separated by semicolons in one pass
  • Backtick, single-quote, and double-quote strings are handled correctly, so column names with spaces are preserved
  • Named (:param) and positional (?) parameters are left untouched by both beautify and minify

FAQ

Does the formatter change the logic of my SQL?

No. The formatter only adjusts whitespace, newlines, and optionally keyword casing. It does not reorder clauses, add or remove any tokens, or interpret the query semantics.

Are SQL comments preserved?

Yes in Beautify mode — both line comments (--) and block comments (/* */) are kept and placed on their own lines. In Minify mode all comments are stripped to achieve the smallest possible output.

Which SQL dialects are supported?

The formatter handles standard SQL and is compatible with MySQL, PostgreSQL, SQLite, and MS SQL Server syntax. Dialect-specific functions and types are treated as identifiers and passed through unchanged.

Can I format very large SQL files?

Yes. The formatter runs entirely in your browser using JavaScript — there is no file size limit imposed by the server. Very large files may take a moment depending on your device speed.

Why does the indentation look different from my IDE?

The formatter uses a fixed set of top-level clause keywords to decide where to break lines. IDE formatters often use a full parser for more context-aware formatting. For most queries the output will be identical or very close.

Report an issue