SQL Formatter
Paste a SQL query, pick a dialect, and format it in your browser.
About this tool
Format a SQL query
Paste a query and choose Format SQL. The sample below is the example on this page, formatted for MySQL with upper-case keywords, two-space indents, and AND on the next line. Copy or download the result as query.sql.
SELECT
id,
name
FROM
users
WHERE
active = 1
AND role IN ('admin', 'editor')
ORDER BY
name;
SQL beautifier and pretty print
Format SQL is the SQL format, the SQL beautifier, and the SQL pretty print. It adds line breaks and indentation. Upper case and lower case change keywords such as SELECT and WHERE. Text inside quotes stays as you typed it. Keep as typed leaves the keywords alone. AND and OR can break before the operator or after it.
MySQL, PostgreSQL, SQL Server, SQLite, and PL/SQL
Choose SQL, MySQL, MariaDB, PostgreSQL, SQLite, SQL Server, PL/SQL, BigQuery, Snowflake, or Redshift. MySQL keeps backtick names. PostgreSQL keeps casts such as ::jsonb and treats ILIKE as a keyword. SQL Server keeps bracketed names. The layout comes from sql-formatter, an MIT-licensed open-source library.
What this SQL formatter does not do
It does not connect to a database, run the query, or check that a table exists. A misspelled word stays as you typed it. It does not minify SQL onto one line, and it does not return a parse tree or a query plan. An unfinished quote or parenthesis is underlined. The part before it is still formatted, and the unfinished part stays as you typed it. If laying the query out would split a quote or a comment, that query is left as you typed it. Statements stay separated by a semicolon. Stored procedures are outside what the formatter supports.
Frequently Asked Questions
How do I format a SQL query?
Paste the SQL query, choose the dialect, and click Format SQL. The formatted query appears below. Copy it or download query.sql. The example on this page puts each selected column on its own line and breaks before AND.
Is a SQL beautifier the same as pretty print?
Yes. On this SQL formatter, beautify, SQL pretty print, SQL format, and format SQL are the same button. It adds line breaks and indentation. AND and OR can sit before or after the line break. It can also change keyword case. Words inside quotes are not changed.
Can I format MySQL, PostgreSQL, and SQL Server online?
Yes. This SQL formatter online also covers MariaDB, SQLite, PL/SQL, BigQuery, Snowflake, Redshift, and standard SQL. The query stays in your browser.
Does this SQL formatter run, validate, or minify the query?
No. It does not run the query or check that a table exists. It does not minify SQL onto one line. It does not return a parse tree or a query plan. A misspelled word is left as you typed it. An unfinished quote or parenthesis is underlined. The part before it is still formatted, and the unfinished part stays as you typed it. If laying the query out would split a quote or a comment, that query is left as you typed it. Statements stay separated by a semicolon, and stored procedures are not formatted.
How do I beautify a one-line SQL query?
Paste the one-line query and click Format SQL. The SQL beautifier adds line breaks and indentation. Choose 2 spaces or 4 spaces, and choose whether AND and OR break before the operator or after it. Upper case, lower case, or Keep as typed applies to keywords such as SELECT and WHERE. Text inside quotes stays as you typed it. If the formatted query is taller than the box, Expand shows the whole query on the page. Copy it or download query.sql.
What is a SQL formatter?
A SQL formatter, also called a SQL beautifier or SQL pretty print, lays a query out so it is easier to read. It adds line breaks and indentation, and it can change keyword case. It does not run the query or check that a table exists. On this page, Format SQL does that in your browser.
Is a SQL minifier the same as a SQL formatter?
No. A SQL minifier packs a query onto fewer lines. This SQL formatter does the opposite: it adds line breaks and indentation. It does not minify SQL onto one line.
Does formatting SQL change quotes, comments, or names?
Text inside quotes stays as you typed it. A closed comment stays, though a block comment may gain indent on a continuation line. An unfinished /* is not rewritten to / *. A nested block comment keeps */. If laying the query out would split a quote or a comment, the query is left as you typed it. Upper case and lower case change keywords such as SELECT. Function names such as count stay as typed. In PL/SQL, name is a keyword, so upper case writes NAME. A misspelled word such as selec stays misspelled.
Does this online SQL formatter upload my query?
No. This SQL formatter online runs in your browser. The query is not uploaded. Copy the result or download query.sql on your own computer.
How do I format SQL in VS Code or SSMS?
This page does not install into VS Code, SSMS, Notepad++, or Sublime. Paste the query here and click Format SQL. Choose SQL, MySQL, MariaDB, PostgreSQL, SQLite, SQL Server, PL/SQL, BigQuery, Snowflake, or Redshift.
Last updated:
Build with Phoenix Code
Open the formatted query in Phoenix Code and edit it with syntax highlighting next to the rest of your project.