Skip to content

SQL Formatter and Prettifier

Format SQL queries with keyword uppercasing, proper indentation, and dialect support.

SQL Formatter and Prettifier tool

Loading...

Example

Input: select id, name from users where active = 1 order by name

Result: SELECT / id, / name / FROM / users / WHERE / active = 1 / ORDER BY / name (clause bodies indented 2 spaces)

Keywords are uppercased and each clause starts on a new line with its contents indented below it.

  1. Paste your SQL query - whether a single-line statement or a complex multi-join query - into the input area.
  2. Select your SQL dialect (Standard SQL, MySQL, PostgreSQL, SQLite, T-SQL, or PL/SQL) for dialect-specific parsing.
  3. Click "Format SQL" to reformat the query with uppercase keywords and 2-space indentation.
  4. View the beautifully formatted SQL with uppercase keywords, indented clauses, and one column per line.
  5. Optionally click Minify to compress the SQL into a single compact line instead.
  6. Click the copy button to copy the formatted SQL for use in your database client or application.

Making SQL Queries Readable

An SQL formatter rewrites a query so each clause starts on its own line, with keywords in uppercase and contents indented below. select id, name from users where active = 1 becomes SELECT with id and name on their own lines, then FROM users, then WHERE active = 1.

Queries copied from logs, ORMs or old code often arrive as one long line. Formatting shows the structure at a glance: which columns are selected, how tables are joined, where each condition sits, and how subqueries and WITH clauses nest. That makes reviews and debugging much faster. The formatter changes only whitespace and keyword case, so the query means exactly the same thing.

Pick a dialect before you format: Standard SQL, MySQL, PostgreSQL, SQLite, T-SQL (SQL Server) or PL/SQL (Oracle). The dialect tells the parser how that database quotes names and which operators exist, such as backticks in MySQL or square brackets in T-SQL. If a statement does not parse, you see the first line of the error. The style is fixed: uppercase keywords, 2-space indentation and one column per line. Minify goes the other way and packs the query onto one line. It removes comments and extra spaces but never touches string literals, quoted names, MySQL /*! */ comments or /*+ */ optimizer hints. That helps when a query has to fit in code, a log line or a URL. For other formats, the JSON Formatter and the XML Formatter work the same way.

Frequently Asked Questions

No. Only line breaks, indentation and the case of keywords change. Table names, column names, values, aliases and the order of everything stay the same, so the database runs the formatted query exactly like the original.
Choose the database the query runs on. The dialect controls how names are quoted, which keywords and operators are recognized and how comments are read. Standard SQL works for simple queries, but syntax such as MySQL backticks, PostgreSQL :: casts or T-SQL square brackets formats best with the matching dialect.
The parser could not read part of the statement. The most common cause is a dialect mismatch, such as T-SQL square brackets with MySQL selected. Unfinished queries and template placeholders such as {{table}} can also fail. Read the first line of the error, switch dialect, or replace placeholders with plain names first.
Formatting keeps your -- and /* */ comments in place. Minify removes them to save space, except MySQL executable comments (/*! ... */) and optimizer hints (/*+ ... */), because those change how the query runs. In MySQL mode, # comments are removed by Minify as well.
No. The style is fixed so everyone gets the same result: uppercase keywords, 2-space indentation and each selected column on its own line. The only setting is the dialect. If your team uses a different style, a configurable formatter in your editor or CI pipeline is a better fit.

Related Tools

JSON Formatter and Validator

Format, validate, beautify, and minify JSON data with a collapsible tree view and line-and-column error detection.

Developer Tools

CSS Minifier

Minify CSS by removing whitespace, comments, and redundant code to reduce file size.

Developer Tools

JavaScript Minifier

Minify JavaScript by removing whitespace, line breaks, and comments for smaller files, without renaming your code.

Developer Tools

Regex Tester

Test regular expressions with real-time match highlighting, group capture display, and a pattern library.

Developer Tools

JSON to CSV Converter

Convert a JSON array of objects to CSV with automatic column headers, and convert CSV back to JSON in the same tool.

Developer Tools

CSV to JSON Converter

Convert CSV data to a JSON array of objects with header mapping and automatic comma, semicolon, or tab detection.

Developer Tools