Free online tool. All processing is client-side. No signup needed.
An SQL Prettifier (formatter) transforms messy, one-line, or inconsistently-written SQL queries into clean, consistently indented, readable SQL. Database queries often start as compact inline strings in application code — `SELECT a.id, a.name, b.total FROM users a LEFT JOIN orders b ON a.id=b.user_id WHERE a.status='active' AND b.total>100 ORDER BY b.total DESC` — and become nearly impossible to debug. This formatter adds consistent capitalization of keywords, line breaks at major clauses, and proper indentation of subqueries.
Paste SQL. The formatter identifies keywords (SELECT, FROM, WHERE, JOIN, GROUP BY, ORDER BY, HAVING, INSERT, UPDATE, DELETE, CREATE, ALTER), and restructures the query into a readable format: each major clause on a new line, column names aligned, subqueries indented, JOIN conditions clearly placed. It respects the original SQL dialect (MySQL, PostgreSQL, SQLite, SQL Server) and can transform between styles: uppercase keywords, lowercase keywords, or capitalize first letter.
Formatting Rules:\n\nMajor Clauses on New Lines:\nSELECT\n column1,\n column2,\n aggregate(col) AS alias\nFROM table\nJOIN other_table ON condition\nWHERE condition\n AND sub_condition\nGROUP BY column\nHAVING aggregate_condition\nORDER BY column DESC\nLIMIT 10;\n\nSubquery Indentation:\nSELECT *\nFROM (\n SELECT id, MAX(total)\n FROM orders\n GROUP BY id\n) AS sub\nWHERE sub.total > 100;\n\nINSERT INTO table (col1, col2)\nVALUES\n (val1, val2),\n (val3, val4);\n\nUPDATE table\nSET\n col1 = val1,\n col2 = val2\nWHERE condition;
There's no single standard, but the most common conventions: keywords in UPPER CASE, table/column names in lower_case, each major clause (SELECT, FROM, WHERE, etc.) on its own line, columns comma-separated with each on its own line. The key is consistency.
Our formatter handles standard SQL and has dialect awareness for MySQL, PostgreSQL, SQLite, SQL Server, and Oracle. Some dialect-specific syntax (e.g., PostgreSQL's :: casting, MySQL's backtick quoting) is preserved.
Free online Sql Prettify — no signup, 100% client-side processing. All data stays in your browser.