Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / SQL

The Evil That is Select *

4.50/5 (2 votes)
25 Jul 2011CPOL 6.8K  
As a counter, relative indexing from SELECT * queries is most often the cause of the evil. Although we live in a day and age of autogenerated DAL's, using the data reader's indexor that accepts a string is a valid and acceptable alternative to the never use a SELECT * query, in fact, when...
As a counter, relative indexing from SELECT * queries is most often the cause of the "evil". Although we live in a day and age of autogenerated DAL's, using the data reader's indexor that accepts a string is a valid and acceptable alternative to the never use a SELECT * query, in fact, when speed is an issue over many records using the data readers associated GetOrdinal method before your while read loop has timings on par with using the direct indexed method. Readability is also greatly enhanced.

If we are going to go the full, SELECT * is evil route, then I am sure that you fully-qualify the objects in your paths (SELECT [customer].[name] FROM [databaseName].[dbo].[customer]) because if you don't, a change to the connection string will also break your queries.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)