SQL Server - index on a computed column?

后端 未结 4 1309
误落风尘
误落风尘 2020-12-10 11:38

I\'m joining to a table dozens of different times, and every time, I join (or filter) based on the results of a SUBSTRING of one of the columns (it\'s a string, but left-pad

4条回答
  •  春和景丽
    2020-12-10 12:37

    Add a calculated column to your table and create an index on this column.

    ALTER TABLE MyTable
    Add Column CodeHead As LEFT(Code,Len(Code)-4)
    

    Then create an index on this.

    CREATE INDEX CodeHeadIdx ON MyTable.CodeHead
    

提交回复
热议问题