T-SQL 1=1 Performance Hit

前端 未结 8 765
谎友^
谎友^ 2020-12-06 04:33

For my SQL queries, I usually do the following for SELECT statements:

SELECT ...
FROM table t
WHERE 1=1
  AND t.[column1] = @param1
  AND t.[column2] = @para         


        
8条回答
  •  旧时难觅i
    2020-12-06 05:18

    This has no performance impact, but there the SQL text looks like it has been mangled by a SQL injection attack. The '1=1' trick appears in many sql injection based attacks. You just run the risk that some customer of yours someday deploys a 'black box' that monitors SQL traffic and you'll find your app flagged as 'hacked'. Also source code analyzers may flag this. Its a long long shot, of course, but something worth putting into the balance.

提交回复
热议问题