Skip to content
DeveloperTools

SQL Formatter

Private

Input

Output

About this tool

Paste a query, a migration script or a whole stored procedure and read it back laid out for a person: one clause per line, one column per line when the list is long, conditions with AND and OR at the start of each line, subqueries and CASE expressions opened up on their own lines. Short statements that fit on one line stay on one line, so a script of forty small updates does not turn into four hundred lines. The output updates as you type, both panes have line numbers and syntax colouring, and both stay editable.

It speaks the procedural dialects, not only plain SQL. SQL Server and Sybase batches with GO and no semicolons, IF … BEGIN … END and TRY/CATCH; Oracle packages, PL/SQL blocks with DECLARE, EXCEPTION handlers, cursors and LOOPs; PostgreSQL functions inside $$ bodies; MySQL and MariaDB procedures with DELIMITER, handlers and WHILE … DO; SQLite and Db2 scripts. The engine is detected from the text, or you pick it. Keyword casing is conservative on purpose: a column called name, date or status is never uppercased, and a type is only cased where a type can sit.

Wide INSERT statements are laid out as a grid. The column list and every VALUES row share one set of column widths, so each value sits directly under its column name and a row of twelve values can be read without counting commas. When a row is wider than the line it is cut into chunks, and every row is cut at the same places, still aligned. CREATE TABLE definitions line up their types the same way, and the assignments of an UPDATE line up on the equals sign.

Nothing you paste is transmitted. The page is static HTML and the formatting happens in your tab, which makes it safe for production procedures, schema dumps and anything with customer data in the VALUES.

Frequently asked questions

Is my SQL uploaded to a server?

No. The formatter is plain JavaScript running in your browser. There is no backend endpoint, so your queries and procedures never leave your device — you can disconnect from the network and it still works.

Which databases does it support?

PostgreSQL, MySQL and MariaDB, SQLite, SQL Server (T-SQL), Sybase ASE, Oracle (PL/SQL), IBM Db2, and a generic standard SQL mode. The dialect decides how strings, identifiers, comments, variables and batch separators are read, and which procedural shape IF, WHILE and DECLARE take. Leave it on auto-detect and the engine is guessed from the text; the status bar tells you which one it picked.

Does it change what the statements do?

No. Only whitespace and the casing of keywords change. Strings, quoted identifiers, numbers, comments and everything inside a $$ body or a q'[…]' literal are passed through byte for byte. Comments stay where they were, including one at the end of a line that ends with a comma. A statement written on one line and one written on twelve produce the same output.

What does "line width" do?

It is the column the formatter tries not to cross. A clause, a function call or an INSERT row that fits within it stays on one line; one that does not is opened up one item per line. Narrower widths produce taller output; 100 columns suits most editors side by side, 120 a wide screen.

Can the body of a procedure start at the left margin?

Yes. By default the body of a stored procedure, function or trigger sits one level in from its header. Switch the routine body option to flush left and the statements after AS, IS or the outer BEGIN start at the margin instead, so a long procedure does not carry an extra level of indentation on every line. Blocks inside the body, such as an IF … BEGIN … END or a loop, are still indented as usual.

Can it line up parameter and variable types?

Yes. Set declarations to aligned and the parameters of a procedure or function, and the variables of a DECLARE, go one per line with their names, types and defaults (= NULL, DEFAULT, OUT) lined up in columns, the way many teams write stored procedures by hand. A DECLARE of a single variable stays on one line. Left on compact, they keep the shorter layout, joined on one line when they fit. The named arguments of an EXEC have an option of their own: set to aligned, they go one per line with their equals signs in one column (@i_account = …, @o_msg = … out).

What does it not handle yet?

It does not validate SQL against a grammar, so a typo in a keyword goes through unchanged rather than being reported. The only inputs it refuses are ones it cannot read at all: an unterminated string or comment, or unbalanced parentheses, which it reports by line and column. Snowflake, BigQuery and Hive have no dedicated mode yet; standard mode formats their queries but not their scripting extensions.

How large a script can I format?

The limit is your browser memory rather than an upload cap. A 5,000-row INSERT formats in well under a second; past roughly 400 KB the syntax colouring switches off to keep typing smooth, and the text stays fully editable.

Is it really free?

Yes, with no account and no usage limit. The site is funded by ads placed around the tool, never inside your working area.

Arrow keys to navigate, Enter to open, Esc to close