Everyone knows the simple T-SQL “SELECT * ” is bad practice. It can:
Effects the execution plan (Table / Index Scan);
Returns too much data: unnecessary extra reads, memory grant, increases network traffic;
Confusing possibilities: retrieving of columns with the same name from two different tables;
Columns definition changes in the source table, requires manually adding a view for the definition refresh;
… and much more.
So, how can we simply replace a star “ * ” with table column names in a few seconds?
There are a few tricks that are extremely easy to list the column names from the table.
Trick 1:
Find the table, expand it and easily drag “columns” folder to the Query Editor.

Now we can remove “ * ” and any unnecessary columns’ names.

Trick 2:
Find the table, right click on table name, after that choose Script Table as > SELECT To > New Query Editor Window

Now we can remove unwanted columns and keep the necessary columns.

Trick 3:
Select a statement and press Ctrl+Shift+Q

or SSMS > Main menu > Query > Design Query in Editor to open Query Designer

Copy column list from the bottom window of the Designer.
Once again, keep the necessary columns and remove unwanted columns.
It is really cool and easy, right? 🙂
Comments