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

The Evil That is "Select *"

Rate me:
Please Sign up or sign in to vote.
4.43/5 (6 votes)
25 Jul 2011CPOL 12.2K   1   2
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...
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 custom VB Class. I created some Properties and had them filled through a SqlCommand Object which selected from a View. The Properties did not get values. I looked at the View and found select * from table along with some joins. I thought select * would always select all columns and assumed the error was in my code. Only after an hour did I update the View (simply opening the alter view script and running it did the trick, no real changes were necessary). I was amazed to see everything working after that. Getting stuff working is usually satisfying. Getting stuff working without actually changing anything is rather frustrating though...

That was when I renounced select *...
I only use it in ad hoc queries to look for some values, never in production code.

License

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


Written By
CEO JUUN Software
Netherlands Netherlands
Sander Rossel is a Microsoft certified professional developer with experience and expertise in .NET and .NET Core (C#, ASP.NET, and Entity Framework), SQL Server, Azure, Azure DevOps, JavaScript, MongoDB, and other technologies.

He is the owner of JUUN Software, a company specializing in custom software. JUUN Software uses modern, but proven technologies, such as .NET Core, Azure and Azure DevOps.

You can't miss his books on Amazon and his free e-books on Syncfusion!

He wrote a JavaScript LINQ library, arrgh.js (works in IE8+, Edge, Firefox, Chrome, and probably everything else).

Check out his prize-winning articles on CodeProject as well!

Comments and Discussions

 
GeneralThat's crazy ... almost qualifies as 'Views are evil'. Pin
BobJanova26-Jul-11 2:42
BobJanova26-Jul-11 2:42 
GeneralReason for my vote of 5 I've ran into this many times too. ... Pin
Steve Echols25-Jul-11 16:09
Steve Echols25-Jul-11 16:09 

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.