Performance effect of using TOP 1 in a SELECT query

前端 未结 4 834
挽巷
挽巷 2021-02-12 10:28

I have a User table where there are a Username and Application columns. Username may repeat but combination of Username + Application is unique, but I don\'t have the unique con

4条回答
  •  悲哀的现实
    2021-02-12 10:51

    You may get some performance difference from just using top, but the real performance you get by using indexes.

    If you have an index for the UserName and Application fields, the database doesn't even have to touch the table until it has isolated the single record. Also, it will already know from the table statistics that the values are unique, so using top makes no difference.

提交回复
热议问题