Click here to Skip to main content
15,886,769 members
Articles / Programming Languages / SQL
Alternative
Tip/Trick

The Evil That is "Select *"

Rate me:
Please Sign up or sign in to vote.
4.50/5 (2 votes)
25 Jul 2011CPOL 6.5K   1
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)


Written By
Architect ERL GLOBAL, INC
United States United States
My company is ERL GLOBAL, INC. I develop Custom Programming solutions for business of all sizes. I also do Android Programming as I find it a refreshing break from the MS.

Comments and Discussions

 
GeneralReason for my vote of 4 Interesting... Pin
BrianBissell1-Aug-11 16:41
BrianBissell1-Aug-11 16:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.