SQL Server
SELECT * FROM files WHERE name LIKE '100!%' ESCAPE '!';
T-SQL also lets you bracket the wildcard: LIKE '100[%]' matches a literal % without ESCAPE.
% and _ are wildcards until you declare an escape character, and backslash is the worst choice for one.
Filed under Querying
LIKE '100!%' ESCAPE '!' runs unchanged on all five engines. The backslash version does not: MySQL's string parser reads ESCAPE '\' as an unterminated literal, and backslash is a silent default escape in MySQL and PostgreSQL but an ordinary character in SQL Server, SQLite and Oracle. Choose a character that never appears in your data, and escape it too when it does.
To match a literal % or _, put an escape character in front of it and name that character with ESCAPE. The clause is standard and works in all five engines. Pick a character other than backslash and the same SQL text runs everywhere.
SELECT * FROM files WHERE name LIKE '100!%' ESCAPE '!';
T-SQL also lets you bracket the wildcard: LIKE '100[%]' matches a literal % without ESCAPE.
SELECT * FROM files WHERE name LIKE '100!%' ESCAPE '!';
Backslash is the default escape even without ESCAPE, so '100\%' works on its own. ILIKE takes the same ESCAPE clause.
SELECT * FROM files WHERE name LIKE '100!%' ESCAPE '!';
Backslash is the default escape. Writing ESCAPE '\' fails here because the string parser treats \' as an escaped quote; ESCAPE '\\' is the working spelling.
SELECT * FROM files WHERE name LIKE '100!%' ESCAPE '!';
No default escape character: without ESCAPE, a pattern cannot match a literal % or _.
SELECT * FROM files WHERE name LIKE '100!%' ESCAPE '!';
No default escape character. The same clause covers _, as in 'file!_x'.
In SQL Server, SQLite and Oracle, backslash means nothing in LIKE unless you declare it with ESCAPE, so the pattern looks for a literal backslash. In MySQL the string parser may consume the backslash before LIKE sees it. A declared non-backslash escape character avoids both problems.
Yes. _ matches any single character, so LIKE 'file_x' also matches 'fileAx'. Use LIKE 'file!_x' ESCAPE '!'. Underscores are common in identifiers and file names, so this bites more often than %.
It follows the collation. SQL Server and MySQL default collations already ignore case. PostgreSQL has ILIKE. SQLite's LIKE ignores case for ASCII letters by default (PRAGMA case_sensitive_like turns that off). Oracle is case-sensitive: compare UPPER(name) LIKE UPPER(:pattern).
Whether = ignores case depends entirely on the column's collation.
Four engines ship regex today, SQL Server only since 2025; SQLite leaves it to the application.
Doubling the quote works everywhere; three engines offer nicer ways out.
SQLly is a native SQL workbench for macOS, Windows and Linux. Its formatter and plan viewer work in all five dialects.