Click here to Skip to main content
Click here to Skip to main content
Alternative Tip

The Evil That is "Select *"

By , 2 Aug 2011
Rate this:
Please Sign up or sign in to vote.
I'm using this way. SELECT * FROM VIEW. Consider the below Table has following fields(Including Non-display columns).
 
Table Structure
-----------------------------------------------------------------------
tbl_Person
-----------------------------------------------------------------------
ID
PersonCode
PersonName
DateOfBirth
Gender
Address1
Address2
Address3
Zipcode
Phone
Fax
Mobile
Email
Website
CreatedOn
CreatedBy
ModifiedOn
ModifiedBy
Status
-----------------------------------------------------------------------
Now I'm creating View & Stored procedure with only columns which to be displayed(except Audit columns & some other) in UI.
View & Stored Procedure
CREATE VIEW vwPersonDetails
AS
SELECT PersonCode, PersonName, DateOfBirth, Gender, Address1, Address2, Address3, Zipcode, Phone, Fax, Mobile, Email, Website FROM tbl_Person
CREATE PROCEDURE Usp_PersonDetails
AS
SELECT PersonCode, PersonName, DateOfBirth, Gender, Address1, Address2, Address3, Zipcode, Phone, Fax, Mobile, Email, Website FROM tbl_Person
Finally I'm using the below one for execution. If you add new columns in table it won't make any changes in View or stored procedure until the modification. So when ever need to display new columns, I'll change the View or stored procedure.
SELECT * FROM vwPersonDetails
EXEC Usp_PersonDetails

License

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

About the Author

thatraja
Web Developer
India India
Programmer | CodeProject MVP, Mentor | Author | Geek | Blogger | Bachelor | Dude
 
About him & his blog? check out here. Currently he's updating the site, he'll return soon there with more things*.
 
In Codeproject, he posted a blogpost & more than couple of Tip/Tricks, hope he'll write more soon.
 
Favorite techs are MVC, WCF, Mobile, HTML5, CSS3, jQuery, etc.,
 
His hobbies are watching movies, CP, being alone, etc., But now he's working on something*.
 
* - SCAMP???
Follow on   Twitter   Google+   LinkedIn

Comments and Discussions

 
GeneralReason for my vote of 5 Solution makes sense! PinmemberDrABELL4-Aug-11 13:21 
GeneralI'd already proposed that solution to our sql guy, and he sa... PinmvpJohn Simmons / outlaw programmer2-Aug-11 5:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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 | Mobile
Web03 | 2.8.140415.2 | Last Updated 2 Aug 2011
Article Copyright 2011 by thatraja
Everything else Copyright © CodeProject, 1999-2014
Terms of Use
Layout: fixed | fluid