Click here to Skip to main content
12,358,242 members (70,148 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

4.4K views
1 bookmarked
Posted

The Evil That is "Select *"

, 25 Jul 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
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)

Share

About the Author

Sander Rossel
Software Developer
Netherlands Netherlands

Sander Rossel is a professional developer with a working experience in .NET (VB and C#, WinForms, MVC, Entity Framework), JavaScript and SQL Server.

He has an interest in various technologies inlcuding, but not limited to, Functional Programming, NoSQL and Software Design.

He seeks to educate others on his blog, Sander's bits - Writing the code you need, and on his CodeProject profile.


You may also be interested in...

Comments and Discussions

 
GeneralThat's crazy ... almost qualifies as 'Views are evil'. Pin
BobJanova26-Jul-11 2:42
memberBobJanova26-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
memberSteve 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.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.160621.1 | Last Updated 25 Jul 2011
Article Copyright 2011 by Sander Rossel
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid