Why is query with phone = N'1234' slower than phone = '1234'?

前端 未结 3 1652
醉话见心
醉话见心 2021-02-01 01:09

I have a field which is a varchar(20)

When this query is executed, it is fast (Uses index seek):

SELECT * FROM [dbo].[phone] WHERE phone = \'5554474477\'         


        
3条回答
  •  南旧
    南旧 (楼主)
    2021-02-01 01:42

     SELECT * FROM [dbo].[phone] WHERE phone = N'5554474477'
    

    is interpreted as

     SELECT * from [dbo].[phone] WHERE CAST(phone as NVARCHAR) = N'5554474477'
    

    which prevents index usage

提交回复
热议问题