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

The Evil That is "Select *"

Rate me:
Please Sign up or sign in to vote.
5.00/5 (5 votes)
2 Aug 2011CPOL 8.7K   2   2
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)


Written By
Team Leader
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralReason for my vote of 5 Solution makes sense! Pin
DrABELL4-Aug-11 13:21
DrABELL4-Aug-11 13:21 
GeneralI'd already proposed that solution to our sql guy, and he sa... Pin
#realJSOP2-Aug-11 5:06
mve#realJSOP2-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.