SQL formatter
Format and beautify SQL queries for MySQL, PostgreSQL, SQL Server, Oracle, SQLite, BigQuery and more, checked to change only the layout. Nothing is uploaded.
- Runs in your browser
- Nothing is uploaded
- Free, no sign-up
Paste or open SQL to format it. Nothing you add leaves this page.
How it works
The SQL beautifier puts each clause of a query on its own line and indents what belongs to it: the columns after SELECT, the tables and joins after FROM, each AND and OR condition, subqueries one step further in. Long lists of values in an INSERT stay one row to a line. Strings, quoted names like "Order" or `order`, numbers and comments are kept exactly as written. Formatting a formatted query again changes nothing.
The formatting itself is done by the open-source sql-formatter library, which knows the keywords and functions of each database. The page doesn't take its result on trust: it reads the input and the result with its own SQL reader, written separately, and compares them piece by piece. Only spaces, line breaks and, if you asked, the case of keywords may differ, and an operator like <= or :: must not be split. We ran it on more than 16,000 queries from database test suites, and on more than 10,000 PostgreSQL ones, PostgreSQL's own parser read every result as the same query as its input.
Lines that a command-line client reads itself, rather than the database, keep their own line as written, and the SQL between them is formatted on its own: MySQL's DELIMITER (statements then end with the new delimiter, so stored procedures stay whole), psql's backslash commands, GO in SQL Server scripts, a lone / in SQL*Plus and the dot commands of SQLite and DuckDB. Formatting runs in a background worker inside this tab, so long scripts don't freeze the page, and spell checking is off in the box so the browser doesn't send what you paste off for checking.
Questions
How do I format a SQL query?
Paste the query into the box or open a .sql file, and pick the database it is written for. The page formats it as you type: each clause (SELECT, FROM, WHERE, GROUP BY…) starts its own line, the columns and conditions under it are indented, and keywords are in upper case, or lower case, or left as you wrote them. Copy the result or download it as a .sql file.
Is it safe to paste SQL into an online SQL formatter?
Only into one that doesn't upload it. In 2025 security researchers found tens of thousands of saved snippets, full of passwords and keys, on two popular code formatting sites, behind share links anyone could guess. Queries hold table names and customer data, and scripts sometimes hold passwords. This page formats the SQL in your browser: it is never sent to a server, saved, or put in the page address, and there is no save or share button that could leak it.
Can a SQL formatter change what my query does?
It can if it misreads the SQL, for example by splitting an operator or joining two words. This page checks every result: it reads the formatted SQL again with its own reader, which follows your database's rules for strings, quoted names and comments, and shows it only if every word, value, symbol and comment is still there in the same order. If anything else changed, it shows nothing and says where. Table names after FROM, JOIN, INTO, UPDATE and TABLE keep the case you wrote, because MySQL on Linux tells upper and lower case apart in them.
Which databases does this SQL formatter support?
MySQL, MariaDB, PostgreSQL, SQL Server (T-SQL), Oracle (PL/SQL), SQLite, BigQuery, Snowflake, Amazon Redshift, Spark SQL and Databricks, DuckDB, Trino and Presto (Athena), IBM Db2, Hive and ClickHouse, and standard SQL. Pick the one the query is written for, because they write strings, quoted names and comments differently: in MySQL a # starts a comment and \' is a quote inside a string, in SQL Server [Order] is a name, and in PostgreSQL $$ starts a function body.
Limits
This is a SQL query formatter, not a validator. It reads the SQL only as far as layout needs, so a misspelt column or a missing table passes through. SQL it can't read at all gets the line and column where it stopped, and with Standard SQL picked the page says if another database's rules read it. Rare syntax, like Snowflake's stage paths or Oracle's JSON_OBJECT with colons, isn't read; the check above also turns away a few pieces the formatter would misplace, so you get your SQL back unchanged or not at all.
Upper or lower case applies to the words the database reserves, its data types and its built-in functions. A column named like one of them, such as text or date, is changed too. That is harmless in most databases, but if your SQL Server database uses a case-sensitive collation, pick “As written”. Code inside a function body written as a string or between $$, such as PL/pgSQL, is kept as written.
The limit is 1,000,000 characters (about 1 MB); bigger dumps are better formatted with your database's own tools. Results over 200,000 characters are shown without colours to keep the page quick. Files are read as UTF-8 or UTF-16 (SQL Server Management Studio saves scripts as UTF-16), else as Windows-1252, and saved as UTF-8.
For JSON and XML there are the JSON formatter and XML formatter, and text compare shows what changed between two versions of a query.
Privacy
This tool runs entirely in your browser. The files you open and what you type are never sent to a server, and nothing is stored after you close the page. See the privacy page.
Related tools
JSON formatter and validator
Format, beautify, minify and validate JSON, with errors explained by line and column and a tree view. Your JSON is never uploaded or saved.
XML formatter and validator
Format, beautify or minify XML and check it is well-formed, with errors explained by line and column and a tree view. Your XML is never uploaded or saved.
Text compare (diff checker)
Compare two texts, JSON files, PDFs or Word documents and see what changed, side by side. JSON is compared by meaning, so key order doesn't count. No upload.