How to use the sql validator
- Paste your SQL query into the text area above.
- The sql validator tokenizes the input immediately as you type or paste.
- Review the output panel for any reported syntax issues or a confirmation that no problems were found.
- Fix the highlighted errors in your source editor and re-paste to verify.
How the tokenizer works
The validator uses a hand-written state machine to break your SQL into tokens: identifiers, keywords, numbers, strings, operators, punctuation and comments. It scans character by character, tracking whether it is inside a string literal, a quoted identifier or a comment block.
For example, when the scanner encounters a single quote ('), it enters string mode and consumes characters until it finds another single quote. If two single quotes appear consecutively (''), they are treated as an escaped quote within the string rather than a closing delimiter. This mirrors standard SQL behavior. Once all tokens are extracted, the validator applies structural rules to detect problems like consecutive commas or unbalanced parentheses.
What this sql validator checks
This tool performs structural validation, not semantic analysis. It catches the following categories of errors:
- Unmatched quotes: single quotes for strings, double quotes for identifiers and backticks for MySQL-style identifiers.
- Unclosed comments: block comments opened with
/*but never closed with*/. - Unbalanced parentheses: more opening than closing brackets, or vice versa.
- Consecutive commas: two commas without an expression between them, such as
SELECT a,, b. - Missing clauses: a
SELECTstatement that lacks aFROMclause (unless it only selects literals or expressions).
It does not verify table names, column existence, data types or dialect-specific grammar, and it cannot tell that a keyword is misspelled or that clauses are in the wrong order. A clean result means the structure is balanced, not that the database will accept the query.
Dialect limitations
SQL has many dialects: PostgreSQL, MySQL, SQL Server, SQLite and Oracle each extend the standard in different ways. This sql validator targets the common structural core shared by most dialects. It recognizes standard string escaping (doubled quotes) and both line comments (--) and block comments (/* */).
PostgreSQL dollar-quoted strings ($$...$$) are skipped correctly. It does not parse dialect-specific constructs like MySQL conditional comments (/*! ... */), or T-SQL bracket-quoted identifiers ([name]). If your query relies heavily on these features, the validator may report false positives. For formatting validated queries, you can use a dedicated sql formatter afterward.
Common SQL syntax mistakes
Even experienced developers make small typos that break queries. Here are frequent issues this tool helps catch:
| Mistake | Example | Fix |
|---|---|---|
| Doubled comma | SELECT a,, b | Remove the extra comma |
| Missing closing quote | WHERE name = 'Alice | Add the trailing ' |
| Unclosed parenthesis | COUNT(DISTINCT id | Add ) |
| Unterminated comment | /* note SELECT 1; | Add */ |
Catching these before sending a query to the database saves time debugging cryptic server error messages.
Worked examples
| Example | Input | Result |
|---|---|---|
| Valid SELECT | SQL query: SELECT id, name FROM users WHERE active = 1; | No syntax issues detected. The query structure looks valid. |
| Unmatched string quote | SQL query: SELECT * FROM users WHERE name = 'O'Brien'; | Found 1 issue(s): / 1. Unmatched single quote (string literal) near position 41. |
| Unclosed block comment | SQL query: SELECT /* missing end / FROM users; | Found 2 issue(s): / 1. Unclosed block comment starting near position 7. / 2. The statement stops after SELECT at the end: something is missing. |
| Missing FROM clause | SQL query: SELECT id, name WHERE active = 1; | Found 1 issue(s): / 1. SELECT statement appears to be missing a FROM clause. |
FAQ
Does this sql validator connect to my database?
No. The tool analyzes your query text locally using a tokenizer. It never connects to any database or sends your SQL over the network.
Can it validate stored procedures or triggers?
It checks the structural syntax of any SQL text you paste, including procedural blocks. However, it does not understand dialect-specific procedural extensions like PL/pgSQL or T-SQL control flow deeply.
Why does it flag my PostgreSQL dollar-quoted string?
Dollar quotes such as $$...$$ and $tag$...$tag$ are recognised and their contents are skipped. If you still see a report, check that the closing tag matches the opening tag exactly. Backslash escapes inside strings (MySQL) are not recognised.
Does it check if my table or column names exist?
No. This is a structural syntax checker, not a semantic analyzer. It cannot verify schema objects because it has no connection to your database.
How are escaped quotes handled?
Standard SQL escapes a single quote inside a string by doubling it: 'it''s'. The tokenizer recognizes this pattern correctly and will not report an unmatched quote.
Is this suitable for checking dynamic SQL built in application code?
You can paste the final assembled query string here to verify its structure. Do not paste raw application code containing string concatenation variables, as those are not valid SQL tokens.