65.9K
CodeProject is changing. Read more.
Home

The Evil That is "Select *"

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.50/5 (2 votes)

Jul 25, 2011

CPOL
viewsIcon

6840

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.