Performance Difference in comparing integers and comparing strings

前端 未结 4 2181
攒了一身酷
攒了一身酷 2021-02-07 02:24

Can anyone provide any concrete evidence of performance when comparing

int = int

and:

string = string

in

4条回答
  •  鱼传尺愫
    2021-02-07 02:35

    As Steve pointed out in the comments, the presence and constitution of indexes will greatly impact your results; however, since SQL Server works with pages to lookup data, and narrower column types can store more data per page, using a narrow type can perform better than a wider type where there are more values to consider.

    So, if you have a small table (few rows), it probably doesn't matter; big table? Put an index on the int column and it will probably out-perform an indexed varchar column.

    Of course, what constitutes large or small tables depends on your hardware.

提交回复
热议问题