Saved

Press the star next to a tool's name to save it.

All my tools

SQL Validator

This SQL validator checks the syntax of your SQL for MySQL, PostgreSQL, SQLite, SQL Server or MariaDB and points to the line and column of any error.

Restored your last values ·

Separate several statements with semicolons. The checker looks at syntax only, so it doesn't need your database or your data.

Checking…

Your SQL is checked in your browser. Nothing is uploaded or run.

Result

Paste SQL and press Validate SQL.

Recent results

A SQL validator checks whether a SQL query is written correctly before you run it. Paste one or more statements, pick your database, and this SQL validator parses them with a grammar for that database. If the syntax is valid, it lists the statements and the tables they use. If there's a mistake, it shows the line and column where the parser got stuck, with a marker under the exact spot, so you can fix it quickly.

How to use the SQL validator

  1. Paste your SQL. Separate several statements with semicolons.
  2. Choose the database: MySQL, PostgreSQL, SQLite, SQL Server (T-SQL) or MariaDB. MySQL is the default.
  3. Press Validate SQL. The first check loads the grammar for that database, which takes a moment.
  4. Read the result. Valid SQL shows the statement types and table names. Invalid SQL shows the line, the column and the text found there.
  5. Fix and validate again until it passes.

Why the database matters

The syntax of SQL is defined by the ISO/IEC 9075 standard, but SQL code isn't completely portable between database systems without changes. Each product adds its own features and keeps its own quirks: identifiers are quoted with backticks in MySQL and with double quotes in PostgreSQL, SQL Server uses TOP where MySQL uses LIMIT, and so on. That's why the validator asks which database you use. A query can be valid for one and invalid for another, so if it fails, check that the right database is selected.

Worked examples

A valid query. Paste SELECT id, name FROM users WHERE age > 30 ORDER BY name; with MySQL selected. The result says Valid MySQL SQL: 1 statement, lists the statement as SELECT, and shows users as the table used.

A query that stops too early. Paste SELECT id, name FROM users WHERE and validate. The result is a syntax error on line 1, column 33, and the message says the SQL ends too early: the WHERE clause needs a condition after it.

A misspelled keyword. Paste SELEC id FROM users. The parser can't treat SELEC as a command, so it reports an error on line 1, near the i of id. The real mistake is the word just before the marker, which is common: a parser reports the first place it can no longer make sense of the text.

What the validator checks

  • Keywords and their order, such as SELECT … FROM … WHERE … GROUP BY … ORDER BY.
  • Punctuation: commas between columns, matching brackets and closed quotes.
  • Expressions: operators, function calls such as COUNT(*), CASE expressions and subqueries.
  • Several statement types: SELECT, INSERT, UPDATE, DELETE, CREATE TABLE and more, in one paste.

What it can't check

Syntax is only half the story. The validator doesn't connect to a database, so it can't tell whether a table or column exists, whether the data types match, or whether you have permission to run the query. A query can be perfectly valid and still fail with an error such as unknown column when you run it. Use this tool to catch typing and structure mistakes early, then test the query against a copy of your database.

Reading an error

The marker points at the first character the parser couldn't accept. Look at that spot and a little before it. A missing comma between two column names, for example, is usually reported at the second name. An unclosed quote or bracket can push the error to the end of the text, because everything after it is read as part of the string or group. When the message says the SQL ends too early, something is missing at the very end: a condition, a closing bracket or a closing quote.

Your privacy

Queries often contain table names, customer data or business logic. The SQL is parsed in your browser and never uploaded, stored or run anywhere.

Dialects at a glance

DatabaseQuotes for namesLimit rows
MySQL and MariaDB`backticks`LIMIT 10
PostgreSQL"double quotes"LIMIT 10
SQLite"double quotes"LIMIT 10
SQL Server[square brackets]SELECT TOP 10

These differences are the most common reason a query copied from one system fails in another. If a query uses features from a different product, switch the database to that one and validate again.

Working with long scripts

You can paste a whole migration or seed script, with many statements separated by semicolons. The validator stops at the first syntax error it meets and shows where it is. Fix that one, validate again, and repeat until the whole script passes. Comments written with -- or /* */ are allowed and ignored.

Who it's for

Students learning SQL can check homework queries before running them. Developers can check a query pasted from a ticket or a code review. Analysts can make sure a report query is well formed before sending it to a busy database. In every case, catching a missing comma or bracket here is quicker than waiting for an error from the server.

Common mistakes

  • The wrong database selected. Backticks fail in SQL Server; TOP fails in MySQL.
  • A trailing comma before FROM, as in SELECT a, b, FROM t.
  • Single quotes for names where the database expects identifier quotes.
  • Reserved words as names, such as a column called order, without quoting them.

What next

Use this often? Add SQL Validato to your Home screen.

Frequently asked questions

What does the SQL validator check?

It parses your SQL with a grammar for the database you choose and reports whether the syntax is valid, with the line and column of the first error if it isn't.

Does the SQL validator run my query?

No. It only checks the syntax in your browser. It never connects to a database, and nothing is uploaded.

Which databases does it support?

MySQL, PostgreSQL, SQLite, SQL Server (T-SQL) and MariaDB. Pick the one you use, because syntax differs between them.

Why is the error marked after the real mistake?

A parser reports the first spot it can't make sense of, which is often just after the actual typo, so check a little before the marker.

Can valid SQL still fail when I run it?

Yes. The validator can't know whether your tables and columns exist or whether you have permission to use them.

What went wrong?

We only receive the reason you pick, never what you typed into the tool.

Thanks for your feedback.

More Developer Tools