T-SQL

SELECT – Returning specific columns

There are many times where returning all the data held within all the columns in a table are unnecessary and inefficient.

For example.

SELECT * FROM HumanResources.Department

If you expand out the HumanResources.Department then you will get a list of the columns as well as some information on the columns.

1

To get only the DepartmentID and Name columns the following query would be needed.

SELECT DepartmentID,Name FROM HumanResources.Department

2

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.