r/SQLServer • • Oct 15 '19

Blog How to Think Like the SQL Server Engine: The Perils of SELECT *

https://www.brentozar.com/archive/2019/10/how-to-think-like-the-sql-server-engine-the-perils-of-select/
26 Upvotes

16 comments sorted by

View all comments

2

u/[deleted] Oct 15 '19

Can anyone confirm that select * is optimized for EXISTS and NOT EXISTS?

2

u/ComicOzzy Oct 16 '19 edited Oct 16 '19

It is. I've always written SELECT NULL instead, mostly as a signal to others less familiar with how SQL works that we aren't returning anything. (edit: TBH, it only helps by causing them to go ask or search to find out what is happening, and if it helps them learn, mission accomplished, I guess.)

1

u/sibips Oct 18 '19

It doesn't matter what you select, it only matters if the record exists or not. You can select 1/0 inside an EXISTS and not get an error.