Wednesday, June 7, 2017

How can I get column names from a table in SQL Server?

In this discussion, I want to share the simple query to fetch all column name in specific table of the database.

As you already know that to show that all column name is existing in the table, you use ALT+F1. 

So, there are different short keys and SQL Queries to show column name and details of table. 

Keys and Queries are as follows:
You can use below SQL Query
SYNTAX 1:
SELECT * FROM DB_NAME.INFORMATION_SCHEMA.COLUMNS 
WHERE TABLE_NAME='TABLE_NAME'
EXAMPLE:
SELECT * FROM EMPLOYEEINFO.INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME='EMPLOYEEDETAILS'

You can also use sp_help
SYNTAX 1:
            sp_help <table_name>;
EXAMPLE:
sp_help EMPLOYEEDETAILS

You can use keyboard Short_cut for the above command by Select Table Name (Highlight Table Name) and press ALT + F1.


No comments:

Post a Comment