blog

Home / DeveloperSection / Blogs / Tricks to Replace SELECT * with Column Names

Tricks to Replace SELECT * with Column Names

AVADHESH PATEL3302 04-Sep-2012

You might have heard many times that one should not use SELECT * as there are many disadvantages to the usage of the SELECT *. I also believe that there are always rare occasion when we need every single column of the query. In most of the cases, we only need a few columns of the query and we should retrieve only those columns. SELECT * has many disadvantages. Let me list a few and remaining you can add as a comment.

1.       Retrieves unnecessary columns and increases network traffic

2.       When a new columns are added views needs to be refreshed manually

3.       Leads to usage of sub-optimal execution plan

4.       Uses clustered index in most of the cases instead of using optimal index

5.       It is difficult to debug.

There are two quick tricks for how users can avoid using SELECT * but instead list the column names.

1) Drag the columns folder from SQL Server Management Studio to Query Editor
2) Right Click on Table Name >> Script table as >> SELECT To… >> Select option

It is extremely easy to list the column names in the table.


Updated 18-Sep-2014
Avadhesh Kumar Patel District Project Manager - Aligarh 14 months work experience in Panchayati Raj Department Sector as District Project Manager & 12 months work experience in IT Sector as Software Engineer. :-)

Leave Comment

Comments

Liked By