SQL Server Interview Question #49
What is the difference between % and _ wildcards in LIKE?
SELECT, Filtering, Sorting & Built-in Functions Mid-Level Intermediate
Detailed Explanation
The % wildcard matches zero or more characters. The _ wildcard matches exactly one character.
For example, 'A%' matches values beginning with A regardless of the remaining length, while 'A_' requires exactly one character after A. Bracket expressions can also be used in SQL Server LIKE patterns for character sets and ranges.
Code Example
SELECT *
FROM dbo.Codes
WHERE Code LIKE 'A_';
SELECT *
FROM dbo.Products
WHERE Name LIKE N'%Camera%';