Click here to Skip to main content
15,897,187 members
Articles / Programming Languages / SQL

The Evil That is "Select *"

Rate me:
Please Sign up or sign in to vote.
4.90/5 (36 votes)
10 Aug 2011CPOL2 min read 93.8K   9  
Just say no to SELECT * in your SQL

Alternatives

Members may post updates or alternatives to this current article in order to show different approaches or add new features.

Please Sign up or sign in to vote.
25 Jul 2011Rutvik Dave
I 100% agree with this.Another trick is *if possible* add audit columns at the time of creating/designing the database, i.e.:CreatedOnCreatedByLastModifiedOnLastModifiedByThis could prevent people from using Select *, because generally we don't display such information anywhere, and...
Please Sign up or sign in to vote.
2 Aug 2011RichYards
I agree with this. However, typing all of the columns can be tedious! Now imagine you are working with a table with DOZENS of columns?! SELECT * FROM DENORMALIZEDTABLE1If you are using MS-SQL or writing a query in MS Visual Studio then there is a trick. You can: * write the select *...
Please Sign up or sign in to vote.
2 Aug 2011thatraja
I'm using this way. SELECT * FROM VIEW. Consider the below Table has following fields(Including Non-display columns).Table...
Please Sign up or sign in to vote.
25 Jul 2011Ennis Ray Lynch, Jr.
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...
Please Sign up or sign in to vote.
25 Jul 2011Sander Rossel
Another 'weird feature' of select * is that in Views select * does not select all columns from a table. It selects all columns from a table that were in the table at the time that the View was created. I found that out when I added some columns to a table and wanted to map those columns in a...
Please Sign up or sign in to vote.
1 Aug 2011wizardzz
It also limits SQL's ability to find a proper index to use, hence hindering performance. I wasn't aware of this aspect until a SQL consultant made mention of it. Unfortunately we haven't adopted the policy of dropping the *.

License

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


Written By
Software Developer (Senior) Paddedwall Software
United States United States
I've been paid as a programmer since 1982 with experience in Pascal, and C++ (both self-taught), and began writing Windows programs in 1991 using Visual C++ and MFC. In the 2nd half of 2007, I started writing C# Windows Forms and ASP.Net applications, and have since done WPF, Silverlight, WCF, web services, and Windows services.

My weakest point is that my moments of clarity are too brief to hold a meaningful conversation that requires more than 30 seconds to complete. Thankfully, grunts of agreement are all that is required to conduct most discussions without committing to any particular belief system.

Comments and Discussions