How to generate Select query with all the columns from a table quickly in SQL Server - SQL Server / TSQL Tutorial Part 107

Scenario:

You are new to SQL Server and you want to select all the columns from SQL Server Table to see the data in SSMS.

Solution:

There are multiple ways to quickly select all the columns from a table and run the query to display data for them.

1) Use * 

You can use Select * From SchemaName.TableName

See the green highlighted *, once you use in your Select query , it is going to return all the column from table.

2) Use Select Top X Rows in SSMS
Go to Database in which your table exists, Right Click on the table and then choose Select top X row (x= depends upon your setting for SSMS) and it will generate select query with all the column from a table for you.

How to generate Select query with all the column for SQL Server Table
The below query will be generate with all the column from the table you have selected.
Select all columns quickly from a table for Select query in SQL Server

 3) Drag the Columns to Query Window
If you are not interested to use above two methods, you can open new query window , type Select and then drag the columns tab from the table you would like to use the columns. it will bring all the columns.
How to select all the columns from a table for Select query in SQL Server

Generate Select query with all the columns from a table quickly in SQL Server

Now you can write the rest of the part such as from SchemaName.TableName.

By knowing above methods, it really helps to prepare your queries quickly as sometime we have to select all columns and exclude couple of them. We can generate the query with all the  columns and then delete the columns which are not required from query.



No comments:

Post a Comment