Sometime we may need almost all the columns from a table result. In this scenario we use Star(*) in our select statement i.e. as SELECT * FROM TableName. Using Star(*) in the select statement is BAD. The best approach is selecting the table with column names. In this article we will learn how quickly we can replace Star(*) with column names.
Replace Star(*) in SELECT Statement
It is always a best practice to select the required columns from the table.
SELECT COLUMN1,COLUMN2, COLUMN3......COLUMN(N) FROM TableName
SELECT [WorkId], [WorkItem], [WorkItemStatus] FROM [ToDoApp].[ToDoList].[WorkItems]
If the table has less columns, then we can easily mention the column names, but what if the table has more columns to select?. There is a quick approach to replace star(*) with column names in SSMS. SSMS makes it very simple for us.
If we look into the object explorer, under the table name we have Columns folder. Just DRAG and DROP the Columns Folder to the query editor, right next to the SELECT clause Refer(Fig 3.).
After the Drag and Drop, all the columns in the table will be present in the our SELECT Statement. This is how we can select all the columns in a table quickly.
I assume you all found this Tip more helpful. Please feel free to share your feedbacks in the comment section.
Leave a Reply