Click here to Skip to main content
12,296,833 members (54,746 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

3.5K views
2 bookmarked
Posted

The Evil That is "Select *"

, 2 Aug 2011 CPOL
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...
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)

Share

About the Author

thatraja
Web Developer
India India
Retired from Q/A section & Technical forums since 2014

More coming soon....

You may also be interested in...

Comments and Discussions

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

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.160525.2 | Last Updated 2 Aug 2011
Article Copyright 2011 by thatraja
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid