SQL Formatter & Beautifier
Format SQL queries with consistent indentation and optional uppercase keywords, for 14 dialects including MySQL, PostgreSQL and SQL Server.
How the SQL Formatter & Beautifier works
Reformat a SQL query with each clause on its own line, consistent indentation and optional uppercase keywords. Choose from 14 dialects, including MySQL, PostgreSQL, SQL Server, SQLite, Oracle PL/SQL, BigQuery and Snowflake; formatting runs in your browser with the sql-formatter library.
- Paste your query into SQL query.
- Choose the SQL dialect your database uses, or leave it on Standard SQL.
- Choose an Indent size of 2, 4 or 8 spaces, and switch Uppercase keywords on or off (it starts on).
- Click Format SQL.
- Copy the result from the Formatted panel, or click Download to save it as formatted.sql.
Worked example
Input: select id, name from users u join orders o on o.user_id = u.id where o.total > 100 and u.active = 1 order by name
With Standard SQL, 2-space indent and uppercase keywords on, SELECT, FROM, WHERE and ORDER BY each start a new line. Each selected column, the table and its JOIN line, and each condition is indented two spaces beneath its clause, with AND starting its own line. Multiple statements separated by semicolons are formatted with a blank line between them.
Why the dialect matters
Dialects differ in how identifiers are quoted, which words are keywords and which parameter placeholders are allowed. MySQL and MariaDB use `backticks`, SQL Server uses [brackets], and PostgreSQL uses $1-style parameters. Picking the right dialect lets the formatter recognize that syntax; with the wrong one, it may stop with a parse error such as "Parse error: Unexpected "`a` from t" at line 1 column 8."
Keywords are also dialect-specific, so a column named name is uppercased as NAME under Oracle PL/SQL, where NAME is a keyword.
Available dialects: Standard SQL, MySQL, MariaDB, PostgreSQL, SQLite, SQL Server (T-SQL), Oracle PL/SQL, BigQuery, Snowflake, Redshift, DB2, Spark SQL, Trino / Presto and DuckDB.
What it does not do
It is not a full SQL validator: the formatter stops at syntax it cannot parse, but a query that parses can still have errors, such as a misspelled column or table name. It does not add syntax highlighting. With Uppercase keywords off, keywords keep the case you typed; the tool does not lowercase them.
Formatting runs in your browser; your SQL is not sent to a server.
Frequently asked questions
Which SQL dialects are supported?
Standard SQL, MySQL, MariaDB, PostgreSQL, SQLite, SQL Server (T-SQL), Oracle PL/SQL, BigQuery, Snowflake, Redshift, DB2, Spark SQL, Trino / Presto and DuckDB. Choose the one your database uses so its quoting and keywords are recognized.
Why do I get a parse error?
The formatter met syntax it does not expect for the chosen dialect, such as MySQL backticks with PostgreSQL selected, or an unclosed parenthesis. The message gives the line and column; check the dialect and the SQL at that spot.
Does it check my SQL for errors?
Only partly. Unparseable syntax produces an error, but valid-looking SQL can still fail when you run it, for example because of a wrong column name. Run the query against your database to be sure.
Will formatting change what my query does?
It should not. The formatter changes line breaks, indentation and, if enabled, keyword capitalization. Table names, column names, string values and comments are left as written.
Can I format several queries at once?
Yes. Separate them with semicolons; each statement is formatted and separated from the next by a blank line.
Is my SQL sent to a server?
No. The formatting library is downloaded to your browser when you first click Format SQL and runs there, and the Download button creates the file locally.
Similar Developer tools
Hex to RGB Converter
Convert hexadecimal color codes to RGB color values effortlessly with our Hex to RGB Converter. Perfect for web and graphic designers.
Markdown Previewer
Preview your Markdown content in real-time with our Markdown Previewer. Perfect for documentation, notes, and blog posts.
Base64 Encoder/Decoder
Encode and decode UTF-8 text as standard Base64. Supports Unicode; this is encoding, not encryption.