← All text tools

SQL String Escape Tool

Escape quotes and special characters so text is safe inside a SQL string literal, with separate rules for MySQL and standard SQL.

  • Free
  • No sign-up
  • Works on any device

About SQL String Escape Tool

A single quote inside a SQL string ends it early, which breaks the statement or opens it to injection. In standard SQL, PostgreSQL, SQL Server, SQLite and Oracle the fix is to double the quote, so O'Reilly becomes 'O''Reilly'. MySQL and MariaDB also treat the backslash as an escape character, so backslashes, double quotes, line breaks, NUL and Ctrl+Z are escaped as well. The tool shows the escaped text and the finished literal, can escape percent and underscore for LIKE patterns, and adds the N prefix for non-ASCII text in SQL Server.

How to use SQL String Escape Tool

  1. Paste the text that has to go inside a SQL string.
  2. Choose the database dialect, and tick the LIKE option if the text is a pattern.
  3. Copy the escaped text or the complete literal with its quotes.

Why use this tool?

Also known as

Frequently asked questions

How do I escape a single quote in SQL?

Write it twice. In 'It''s' the doubled quote stands for one quote character. This works in every dialect listed here, and MySQL also accepts a backslash before the quote.

Why does MySQL need different escaping?

By default MySQL gives the backslash a special meaning inside strings, so a lone backslash can swallow the next character. Unless NO_BACKSLASH_ESCAPES is set, backslashes must be doubled.

Is escaping enough to prevent SQL injection?

It is a weak defence that depends on getting the dialect and character set exactly right. Parameterized queries keep data and SQL separate and are the correct fix in application code.

Is SQL String Escape Tool free?

Yes. SQL String Escape Tool on Toolipedia is free to use, with no sign-up and no watermark.

Is it safe to use?

Yes. Everything is worked out in your browser, and nothing you enter is sent to our server.

Does it work on my phone?

Yes. It works in any modern browser on Android and iPhone, as well as on tablets and computers. There's nothing to install.

Do I need an account?

No. Just open the page and use the tool. There's no sign-up and no email needed.

Can I put SQL String Escape Tool on my own website?

Yes. Use the Embed on your site button under the tool to copy a short piece of code and paste it into your page. It is free, needs no account, and the tool keeps working inside your page.

Related tools