Skip to content
YouNeed Tools
Free VPN

SQL Formatter

Paste a query to lay it out clearly, choose upper or lower case keywords and the indent, and copy the result. It also squeezes SQL onto one line.

Output
Keywords
Indent

Formatted on your device. Nothing you paste is sent anywhere.

Worked example

A one-line query copied from a log, select id, email from users where status = 'active' and created_at > '2026-01-01' order by created_at desc limit 50, comes out as:

SELECT
  id,
  email
FROM users
WHERE status = 'active'
  AND created_at > '2026-01-01'
ORDER BY created_at DESC
LIMIT 50

Each clause starts a line, every selected column has its own line and each extra condition sits under WHERE, so a missing condition or a wrong column is easy to spot in a code review.

A readable SQL style

  • One clause per line: SELECT, FROM, JOIN, WHERE, GROUP BY, HAVING, ORDER BY, LIMIT.
  • Put join conditions on an indented ON line, and AND/OR at the start of each condition line.
  • Upper-case keywords and lower-case names is the most common convention; pick one and stick to it.
  • Give tables short aliases (u for users) and always qualify columns when joining.
  • Indent subqueries and consider turning repeated ones into a WITH (CTE) block.

What a simple formatter can’t do

This formatter works from the shape of the text, not a full grammar for each database, so it is fast and forgiving with unfinished queries, but it won’t catch syntax errors, missing commas or unknown columns. Run the query in your database (or EXPLAIN it) to check it. Very unusual syntax, such as MySQL’s DELIMITER commands or Oracle’s q'[ ]' quotes, may not be laid out ideally.

Formatting in reviews and tickets

Long queries pasted into a ticket, chat or pull request are much easier to review once each clause and column has its own line, because a change then shows up as a one-line difference. Keep the original query alongside if exact spacing matters, for instance in a stored view whose definition is compared byte for byte. For queries that are built in code, format the final SQL your program logs, not the code that builds it, to see exactly what the database ran.

Related tools

Sources

Checked on November 26, 2026:

Frequently asked questions

Which SQL dialects does it support?
It formats the common syntax shared by MySQL, MariaDB, PostgreSQL, SQL Server, SQLite, Oracle and BigQuery: SELECT, INSERT, UPDATE, DELETE, joins, subqueries, CTEs and CASE. It reads each dialect’s quoting (`backticks`, "double quotes", [brackets]) and PostgreSQL $$ blocks, but it doesn’t know every vendor keyword and doesn’t check that the SQL is valid.
Will formatting change what my query does?
No. Only whitespace and the case of keywords change. Strings, quoted names, numbers and comments are kept exactly as written.
Can it format stored procedures?
Simple ones. Long procedural code (PL/pgSQL, T-SQL blocks with IF/WHILE) is kept readable but isn’t indented by block; a full IDE formatter does that better.
Why are some words not upper-cased?
Only SQL keywords change case. Table names, column names and function names such as count() or lower() keep the case you typed, so nothing breaks on case-sensitive databases.
What does “One line” do?
It removes comments and squeezes the query onto a single line, handy for log files, code strings and command-line tools.
Is my SQL sent to a server?
No. Queries often include table names and data; they are formatted on your device.

Last updated: 2026-11-26