How to avoid Select *

It is commonly known that you should not use SELECT * when you are writing a query.
Most of the times, we only need a some of the columns that a table has and we should retrieve only those columns.
This are some of the disadvantages of using Select * :

1. Debugging is very difficult and time consuming
2. When the structure of a table is modified by adding new columns views, functions or stored procedures requiere additional atention manually refresh in case of malfunction.
3. Increasead network traffic by retrieving unnecessary columns
4. In most of the situations the clustered index is used instead of the optimal index.
5. Sub-optimal execution plan

Here are two practicle, easy and quick ways to avoid the use of Select * :

1) Drag the Columns folder from SQL Server Management Studio to Query Editor and keep only the columns that you need
2) Right Click on a Table >> Script table AS >> Select to… >> Select an option from : – New query window / – Clipboard / – File / – Agent Job

Lucian Leonte

Powered by CodeReview – Let's make it Better!