Format and beautify SQL queries instantly — convert minified SQL into readable, properly indented queries with keyword capitalisation and clause formatting.
Enter your figures and click Calculate to see your results.
Paste your SQL query, choose to format, format with uppercase keywords or minify, and select your SQL dialect.
Click the Format button. Your code is processed instantly — all formatting runs in your browser with no data sent to servers.
The formatted output appears on the right. Click Copy to grab it, or Download to save as a file. Statistics like size reduction and line count are shown automatically.
Well-formatted SQL is dramatically easier to read, debug, and maintain. Minified SQL hides the query structure, making it hard to spot issues like missing JOIN conditions, incorrect column aliases or logic errors in WHERE clauses. Formatted SQL with consistent keyword capitalisation, aligned clauses and proper indentation is standard practice in professional database development and code review.
SQL has a standard (ANSI SQL) and many vendor-specific extensions. MySQL/MariaDB uses backtick identifiers, LIMIT/OFFSET for pagination, and AUTO_INCREMENT. PostgreSQL uses double-quoted identifiers, LIMIT/OFFSET, SERIAL or GENERATED for auto-increment, and has extensive JSON support. SQL Server uses square bracket identifiers, TOP instead of LIMIT, and IDENTITY for auto-increment. Oracle uses ROWNUM for row limiting and has different date functions.
A query can return the correct results in milliseconds or minutes depending on how it is written. Key optimisation principles: use indexes on columns in WHERE, JOIN and ORDER BY clauses; avoid SELECT * (specify needed columns); avoid functions on indexed columns in WHERE clauses (prevents index use); use JOINs instead of correlated subqueries; use EXPLAIN/EXPLAIN ANALYZE to understand query execution plans; limit rows early with WHERE before grouping.
An index is a data structure (usually a B-tree) that allows the database to find rows without scanning the entire table. Without indexes, queries on large tables can be catastrophically slow. Add indexes on: foreign key columns, columns frequently used in WHERE clauses, columns used in JOINs, columns used in ORDER BY. Downsides: indexes slow INSERT/UPDATE/DELETE operations and consume disk space. Do not over-index — profile queries first.
INNER JOIN returns only rows where there is a match in both tables. LEFT JOIN returns all rows from the left table plus matched rows from the right (unmatched right rows are NULL). RIGHT JOIN is the mirror of LEFT JOIN. FULL OUTER JOIN returns all rows from both tables (NULLs where there is no match on either side). CROSS JOIN returns the Cartesian product of both tables (every row from A paired with every row from B).
Window functions perform calculations across a set of rows related to the current row, without collapsing them into a single output row (unlike GROUP BY). Examples: ROW_NUMBER() OVER (PARTITION BY department ORDER BY salary DESC) numbers employees within each department by salary. LAG(salary) OVER (ORDER BY hire_date) accesses the previous row's salary. Window functions enable ranking, running totals, moving averages and period-over-period comparisons in a single query.
SQL injection lets attackers manipulate queries by inserting malicious input. For example, an attacker enters OR 1=1-- to return all rows, or uses a statement to drop tables entirely. Prevention: always use parameterised queries (prepared statements) or an ORM — never build SQL by concatenating user input as strings. This is the OWASP #1 web security risk. Formatting SQL properly makes it much easier to spot where parameterisation is missing.
Normalisation organises tables to reduce data redundancy and dependency. First Normal Form (1NF): atomic values, no repeating groups. Second Normal Form (2NF): 1NF + no partial dependencies on composite keys. Third Normal Form (3NF): 2NF + no transitive dependencies. BCNF (Boyce-Codd): stricter 3NF. Higher normal forms exist but are less commonly applied. Denormalisation (intentionally adding redundancy) is sometimes done for read performance in reporting and analytics databases.