1

I am new in T-SQL. As far as I know, SELECT * is considered to be a bad practice so I always avoid using SELECT * in my code.

However, my colleague told me that use SELECT * is fine for doing an existence check. For example,

IF EXISTS (SELECT * FROM tb_test WHERE ResourceType = 2)
BEGIN
    --do something
END

"Because the MSSQL Server knows that the statement is doing an existence check, the optimizer will do the right thing." he said.

Is there no performance overhead when I use SELECT * for doing an existence check??

Thanks in advance.

4

1 回答 1

8

你的同事是正确的1。优化器知道实际上不需要检索任何列数据。

但你也是正确的,一般来说SELECT *应该避免。EXISTS检查是证明规则的例外。

1根据我的经验,SO 有点罕见。

于 2013-09-16T07:07:14.517 回答