How to quickly write Select Query in SQL Server - SQL Server / TSQL Tutorial Part 108

You just started working with SQL Server and interested to learn how to select data from a table. Here are some tips for you

1) Select all the columns from a table/ View by using *
You can always use Select * from SchemaName.TableName to display data for all the columns from a table or view. When you use * in Select query, it return you all the columns from table or view.

Let's say that if I want to select all the columns from dbo.TotalSale table , I can use below query
How to select data for all the columns from SQL Server Table by using *


2) Drag the Columns Tab to new query
If you would like to get all the column names for your select query, you will open new query window. Then type Select and Drag the Columns Tab under the table to query window. All the columns will be displayed. If you would like to remove few, you can remove.

Select all the Columns quickly for a table for Select Query in SQL Server


After dragging the Columns Tab, you will see the column names are added to select.
How to generate Select Query with required Columns quickly in SSMS - SQL Server Tutorial


3)  Select Top X Row
Third and easy way to write your select query is, Right click on Table name and then choose Select Top X Rows ( X can be different as per your SSMS option settings). Once you choose it will generate the select query with all the column. You can remove the top x part from select and modify as required.
How to use Select Top X rows to generate select query with all the column names in SQL Server



No comments:

Post a Comment