SQL Server - Query Short-Circuiting?

后端 未结 7 1451
北荒
北荒 2020-12-01 20:00

Do T-SQL queries in SQL Server support short-circuiting?

For instance, I have a situation where I have two database and I\'m comparing data between the two tables to

7条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-01 20:41

    You could add a computed column to the table. Then, index the computed column and use that column in the join.

    Ex:

    Alter Table Table1 Add PaddedId As Right('000000000000' + Id, 12)
    Create Index idx_WhateverIndexNameYouWant On Table1(PaddedId)
    

    Then your query would be...

    select * from table1 where table1.PaddedID ='000000001234'
    

    This will use the index you just created to quickly return the row.

提交回复
热议问题