SQL Statement Splitter
Split a SQL script into numbered statements on top-level semicolons, keeping strings, quoted identifiers and comments intact, locally in your browser.
- Runs locally in your browser
- No upload required
Try it
Supported formats
Privacy
Runs entirely in your browser. Your input is never uploaded, stored, or sent to a third party.
Split the script into 3 statement(s).
How it works
- Tokenised the script, keeping literals, identifiers and comments opaque.
- Cut at each top-level semicolon.
- Trimmed, dropped empty slices and classified each statement.
- A semicolon inside a string, identifier or comment never splits a statement.
Methodology
- Tokenise the script, keeping literals, identifiers and comments opaque.
- Cut at each top-level semicolon (outside parentheses).
- Trim each slice, drop the empty ones and classify the remainder.
Usage
- Paste a SQL script that contains several statements.
- Choose the dialect.
- Run the splitter and copy the numbered statements you need.
Examples
These are examples, not current values: they use fixed inputs, while the interactive tool computes live results in your browser.
A three-statement script
{
"text": "create table t (id int);\ninsert into t values (1);\nselect * from t;",
"dialect": "standard"
}A semicolon inside a string
{
"text": "insert into notes (body) values ('a; b; c');",
"dialect": "postgresql"
}Windows line endings
{
"text": "select 1;\r\nselect 2;\r\n",
"dialect": "tsql"
}Limitations
Scripts are not statements
A migration file or a batch is a sequence of statements. Splitting them safely, without breaking on a semicolon inside a literal, is the first step to reviewing or running them one at a time.
Frequently asked questions
- Will a semicolon inside a string split my statement?
- No. Strings, quoted identifiers and comments are treated as opaque while splitting.
- What happens to an empty statement?
- A statement with only whitespace between separators is dropped; only real statements are returned.
- Is my script uploaded?
- No. The script is split entirely in your browser.
Sources
- ISO/IEC 9075-1:2023: Information technology, Database languages SQL — ISO/IEC
- PostgreSQL Documentation: SQL Syntax, Lexical Structure — PostgreSQL Global Development Group
- MySQL 8.0 Reference Manual: String Literals — Oracle
- SQLite Documentation: SQL Syntax — SQLite Consortium
- Microsoft Learn: Transact-SQL Syntax Conventions — Microsoft
Send feedback
Tell us if this tool helped, report a problem, or suggest a tool. Only the message you type is sent — never the input you used in the tool.
Was this tool useful?
Prefer to write to us directly? See the contact page.