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

Processed entirely in your browser; never uploaded.

Each dialect has its own comment, string and identifier rules.

Statements
3
#1 (ddl)
create table t (id int)
#2 (insert)
insert into t values (1)
#3 (select)
select * from t
-- #1 (ddl)
create table t (id int);
-- #2 (insert)
insert into t values (1);
-- #3 (select)
select * from t;

Supported formats

Input
text/plain
Output
text

Privacy

Runs entirely in your browser. Your input is never uploaded, stored, or sent to a third party.

Processing
In your browser
Privacy level
Browser only

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

  1. Tokenise the script, keeping literals, identifiers and comments opaque.
  2. Cut at each top-level semicolon (outside parentheses).
  3. Trim each slice, drop the empty ones and classify the remainder.

Usage

  1. Paste a SQL script that contains several statements.
  2. Choose the dialect.
  3. 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

jsonSelect to copy
{
  "text": "create table t (id int);\ninsert into t values (1);\nselect * from t;",
  "dialect": "standard"
}

A semicolon inside a string

jsonSelect to copy
{
  "text": "insert into notes (body) values ('a; b; c');",
  "dialect": "postgresql"
}

Windows line endings

jsonSelect to copy
{
  "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

  1. ISO/IEC 9075-1:2023: Information technology, Database languages SQL — ISO/IEC
  2. PostgreSQL Documentation: SQL Syntax, Lexical Structure — PostgreSQL Global Development Group
  3. MySQL 8.0 Reference Manual: String Literals — Oracle
  4. SQLite Documentation: SQL Syntax — SQLite Consortium
  5. Microsoft Learn: Transact-SQL Syntax Conventions — Microsoft