SQL Formatter
Format SQL statements online. The tool breaks a one-line query into readable lines by inserting a line break before keywords such as SELECT, FROM, WHERE, JOIN and ORDER BY, making long statements much easier to read.
FreeOnline Tool
Loading…
How to Use
- Paste the SQL statement you want to format into the input box
- Click "Format" and the reformatted SQL, with a line break before each recognized keyword, appears below
- Click "Load sample data" to see how a longer query with JOIN, WHERE, ORDER BY and LIMIT is laid out
Features
- Recognizes the common SQL keywords SELECT, FROM, WHERE, AND, OR, ORDER BY, GROUP BY, HAVING, LIMIT, INSERT INTO, VALUES, UPDATE, SET, DELETE, CREATE TABLE, JOIN, LEFT JOIN, RIGHT JOIN, ON and UNION
- Inserts a line break before every recognized keyword, turning a query crammed onto one line into a readable multi-line block
- Keyword matching is case-insensitive, so lowercase SQL is recognized and formatted just as well
Use Cases
Reading single-line SQL from logs
Copy a query out of a slow query log or ORM output and reformat it into multiple lines so it is readable while troubleshooting.
Reviewing complex queries
Format a colleague's complex query before a code review so the JOIN and WHERE conditions are easy to follow.
Preparing SQL samples for documentation
Lay out SQL examples neatly when writing technical documentation or training material.
Debugging dynamically built SQL
Queries assembled by code usually come out as one long line, and formatting them makes it much easier to spot a concatenation mistake.
FAQ
Which SQL keywords are supported?
SELECT, FROM, WHERE, AND, OR, ORDER BY, GROUP BY, HAVING, LIMIT, INSERT INTO, VALUES, UPDATE, SET, DELETE, CREATE TABLE, JOIN and its LEFT/RIGHT variants, ON and UNION. Keywords or dialect syntax outside this list simply do not get an extra line break.
Which database dialects does it handle?
Formatting is based on generic SQL keywords and does not apply any special handling for a particular database such as MySQL, PostgreSQL or SQL Server. Standard SQL statements format correctly.
Does formatting change what my query does?
No. Only line breaks are inserted. Keywords, table names, column names and the logical structure of the statement are left untouched, so the query executes exactly as before.
Is my SQL sent to a server?
No. Formatting happens entirely in your browser and nothing is uploaded, so it is safe to paste queries that contain business information.