There are currently three types of SQL Server wildcard characters, "%", "_", "[charlist]", and three are used for fuzzy queries.
The following are presented separately:
1, "%"
"%" is used for any string containing 0 or more characters, instead of the indeterminate part of the query condition, in general, the% wildcard is used to match the following characters, and is a full-text search with a slower speed
Example: SELECT * from PRODUCEDATATB WHERE serialnum like '%2317371611290859 ' This is the query statement that I used to query for other characters in the enterprise production database before the serial number, Execution time is 1250ms
2, "_"
"_" to match any single character
Change the above example to SELECT * from PRODUCEDATATB WHERE serialnum like ' __2317371611290859 ', at which point only the first two bits of the serial number match, the speed is 3 times times higher than the use of "%", Execution time is 420ms
3. "[Charlist]"
Select the data that is included in [] with the beginning of the letter
Example:
The "Persons" table selects people who live in cities that start with "A" or "L" or "N"
The "Persons" table selects people who live in cities that do not start with "A" or "L" or "N"
How to view the execution time of an SQL statement:
A simpler and more straightforward approach:
DECLARE @begin_date datetime
DECLARE @end_date datetime
Select @begin_date = getdate ()
SELECT * from PRODUCEDATATB WHERE serialnum like ' __2317371611290859 ' // Execute SQL statement
--select * from PRODUCEDATATB WHERE serialnum= ' D02317371611290859 '
--select * from PRODUCEDATATB WHERE serialnum like '%2317371611290859 '
Select @end_date = getdate ()
Select DateDiff (MS, @begin_date, @end_date) as ' spents/milliseconds '
wildcard characters in SQL Server