Index on a column with similar and where is the pattern?

I came to the conclusion that, as in the following cases, search / scan. But I didn’t get why it scans in the first case and searches in the second case. I understood the third case.

SELECT c.contactname FROM Sales.Customers c
WHERE c.contactname LIKE '%a'-- Does a Scan 1st Case

SELECT c.contactname FROM Sales.Customers c
WHERE c.contactname LIKE 'a%'-- Does a Seek 2nd Case

SELECT c.contactname FROM Sales.Customers c
WHERE c.contactname LIKE '%a%'-- Does a Scan

If I create an index in the name of the contact that has an example of data below, how will the index tree .. like us, if we build for numbers, then it will compare less than more, and it will move along how the index tree will go in case below.

c.contactname

mark
anna
krishna
nadejda
allen
bob
cab
+5
source share
3 answers

, : . . () , , .

:

        /nadejda
    mark
   /    \krishna
cab
   \    /bob
    anna
        \allen

, a% , , . , C > A, . %a . , , node A. .

+4

, , SQL Server. , .

. contactname - . (, , , , B-, ).

contactname like 'a%', , , "a". , , , . SQL Server like ( ).

contactname like '%a', : " , " a ". , , "a". . , "a" "a". , "z" "a". , .

+4

, , , . , .

allen
anna
bob
cab
krishna
mark
nadejda

, LIKE 'a%' Sql-, , , "" . , LIKE '%A', , -, A.

, .

+4
source

All Articles