SQL Server – Get the Table Structure Using T-SQL

When you are writing a SELECT statement and you just want to limit the number of columns, you would use the​​ sp_help​​ stored procedure to research the underlying table structure as shown​​ below.

 

​​ 

 

 

The​​ sp_help​​ system stored procedure will return all the data about a particular table when you pass the table name into the stored procedure.

 

But If you don't want to sort through all that information, it is possible to get only the names of the columns by executing a query that selects all columns with a false​​ WHERE​​ clause as shown below.

 

SELECT​​ *

FROM​​ [HumanResources].[Employee]

WHERE​​ 1=0

 

 

 

This query tells SQL Server to return all the columns and rows where one equals zero. Because one can never equal zero, SQL Server will return the column names from the table with no data.

Knowledge worth sharing...Share on linkedin
Linkedin
Share on facebook
Facebook
Share on google
Google
Share on twitter
Twitter
Bookmark the permalink.

Leave a Reply

Leave a Reply

Your email address will not be published. Required fields are marked *