Editorials

SQL Newbie Tip – Select *

Here’s an old tip for SQL newbies. Avoid using “SELECT *“. There are lots of performance problems, and potential inaccuracies that may occur by using this syntax.

I don’t mean you should NEVER use SELECT *. When you are doing discovery, don’t know what the table definition is, or forget a column name, don’t hesitate to use this syntax.

The times when you should not use this syntax are found when you are writing stored procedures, writing functions, writing external queries. Anything that can be cached in any fashion should avoid this syntax for ongoing accuracy and performance.

I’ve even seen SELECT COUNT(*). There is no need to have SQL Server materialize all of the columns found behind COUNT(*). Simply use SELECT COUNT(1) instead.

Cheers,

Ben