What is SQL Escaper?
This SQL escape and unescape tool prepares text for use inside a SQL string literal. SQL strings are wrapped in single quotes, so a single quote inside the text, as in O'Brien or it's, ends the string early and causes a syntax error. The standard fix is to double it: O''Brien. The tool also doubles backslashes, which MySQL and MariaDB treat as an escape character by default.
Unescape mode reverses both changes. It is handy for writing one-off queries, seed data and migrations by hand, and for reading escaped values copied from SQL dumps.
How to use SQL Escaper
- Choose Escape to prepare text for a SQL string, or Unescape to reverse the escaping.
- Paste your text into the input panel.
- Copy the result and place it between single quotes in your SQL, for example WHERE name = 'O''Brien'.
- For application code, use parameterized queries instead of escaping by hand.
Key features
- Doubles single quotes for SQL string literals
- Doubles backslashes for MySQL and MariaDB
- Unescape mode reverses both
- Instant output as you type
- Runs entirely in your browser
Common use cases
- Writing INSERT and UPDATE statements with names such as O'Brien by hand
- Preparing seed data and migration scripts
- Reading escaped values from SQL dumps
- Fixing syntax errors caused by apostrophes in queries
- Teaching how SQL string literals work
Technical details & standards
Escaping replaces every ' with '' (the SQL standard way to include a quote in a string literal) and every \ with \\. Unescaping replaces '' with ' and \\ with \.
Doubling single quotes is correct for PostgreSQL, SQL Server, Oracle, SQLite and MySQL. Doubling backslashes is needed for MySQL and MariaDB in their default mode; PostgreSQL treats backslashes literally in standard strings, so there the doubled backslashes would be stored twice. Escaping by hand is for one-off queries only: in application code always use parameterized queries or prepared statements, which prevent SQL injection regardless of the input.
Frequently asked questions
How do I escape a single quote in SQL?
Double it: 'It''s done' stores the value It's done. This works in PostgreSQL, MySQL, SQL Server, Oracle and SQLite.
Does escaping quotes prevent SQL injection?
Not reliably. Escaping rules differ between databases and character sets, and it is easy to miss a case. Use parameterized queries or prepared statements, which send values separately from the SQL text.
Do I need to escape backslashes?
In MySQL and MariaDB by default, yes, because the backslash is an escape character. In PostgreSQL standard strings, SQL Server and SQLite, backslashes are literal, so only double the single quotes there.
How do I escape double quotes in SQL?
Inside a single-quoted string, double quotes need no escaping. Double quotes delimit identifiers in standard SQL; to include one in an identifier, double it ("my""table").
Is my data safe?
Processing happens locally in your browser. Tool input is not sent to CodeUnpack servers.
Does it work offline?
Once the page has loaded, this tool can process input without an internet connection.