SQL Query Analyzer

SQL Query Analyzer

Analyzes SQL queries for validity, performance hints, and potential security issues.
○ Detects syntax errors before execution.
○ Provides optimization tips for query performance.
○ Highlights possible SQL injection or security risks.

Paste your SQL query and press Analyze.

About the SQL Query Analyzer

A query that runs is not necessarily a good query. SELECT * pulls columns nobody uses, a forgotten WHERE on an UPDATE rewrites an entire table, and a string concatenated into dynamic SQL is an open door for SQL injection. Code reviews catch some of these problems; many slip through.

The SQL Query Analyzer parses your query with Microsoft's T-SQL parser (the same grammar SQL Server uses), reports syntax errors with their line and column, and then scans the query for common performance anti-patterns and security risks. It also returns a beautified version of the query with consistent keyword casing and indentation, which makes long joins and nested subqueries far easier to review.

Common uses

  • Sanity-checking a query before running it against a production database.
  • Reviewing SQL in pull requests or legacy stored procedures.
  • Formatting a one-line query copied from application logs or an ORM's SQL output.
  • Teaching or learning which SQL patterns are risky and why.

How to use it

  1. Paste one or more SQL statements into the SQL Query box, or click Try Me.
  2. Press Analyze.
  3. Read the Performance & Security findings, then copy or save the Beautified SQL.

Example

A query with two classic problems:

Input
select * from Orders where CustomerName like '%smith%'
Output
⚠️ Avoid SELECT * for performance; specify columns explicitly.
⚠️ Leading wildcard in LIKE ('%...') prevents index usage.

SELECT *
FROM Orders
WHERE CustomerName LIKE '%smith%'

Tips and common pitfalls

  • SELECT * reads every column, prevents covering indexes from being used and breaks code when columns are added. List the columns you need.
  • A pattern like LIKE '%term%' cannot use a normal B-tree index, so the database scans every row. Consider full-text search for "contains" queries.
  • NOT IN (subquery) returns no rows at all if the subquery contains a NULL. NOT EXISTS is both safer and often faster.
  • UNION removes duplicates, which requires a sort; use UNION ALL when duplicates are impossible or acceptable.
  • Never build SQL by concatenating user input. Use parameters (@id, ? or :id, depending on your driver).

Frequently asked questions

Which SQL dialect is supported?

Syntax validation uses the Microsoft T-SQL parser, so it is exact for SQL Server and Azure SQL. Most standard SQL written for PostgreSQL or MySQL also parses, but dialect-specific features such as LIMIT or RETURNING may be reported as errors.

Does the analyzer connect to my database?

No. It only examines the text of the query. It never connects to a server, so it cannot see your indexes or data volumes — treat the findings as review hints rather than a query plan.

Why is a comment flagged as a security risk?

Attackers often use -- to comment out the rest of a statement during SQL injection (for example ' OR 1=1 --). The warning is a prompt to check that the comment is intentional, not proof of an attack.

How do I see the real performance of a query?

Run it in your database with the execution plan enabled — SET STATISTICS IO ON and the actual execution plan in SQL Server, or EXPLAIN ANALYZE in PostgreSQL.

Related