Wednesday, December 1, 2010

How to read columns index in Microsoft SQL Server 2005

To find out the column name,Column Index etc in a table, we can use the following query, In this regard we have used the system table which is in the SYS schema and the table name is COLUMNS

SELECT C.COLUMN_ID,[COLUMN NAME]=C.NAME
FROM SYS.COLUMNS C
WHERE OBJECT_NAME(C.OBJECT_ID)='Table Name'


If we want to display the output in Ascending or Descending order we should add the following line at the end of the query above.

ORDER BY C.COLUMN_ID DESC 'for Descending order

ORDER BY C.COLUMN_ID ASC ' for Ascending order which is default settings

OUTPUT OF THE ABOVE QUERY

2 comments:

BHATTI said...

Created by Mr.Khalid Bhatti

Faisy said...

Thanks to Mr.Khalid Bhatti for this post.

Faisal.