In SQL Server, we get the table description using below command:
Sp_help TableName
When it displays all column names in a random order. Is there a way If I want to get all column names alphabetically sorted in some order (Descending or Ascending)?
This will help me to have a quick look at the table to see what all columns are present and whether a specific column is present in the table or not.
You may get the List of Column from the System View which is INFORMATION_SCHEMA.COLUMNS
. You can do a Select on the View and Filter by Table there order the List based on any of your desired values as mentioned below:
SELECT
*
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME ='YourTableName'
ORDER BY COLUMN_NAME ASC
There is one more query to achieve this:
SELECT *
FROM sys.COLUMNS where object_id = OBJECT_ID('yourtablename')
ORDER By NAME
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With