Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • SQL : How to get column names of a table in SQL Server ?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 352
    Comment on it

    Often we may be required to get the names of all columns in a table in SQL server. In this post we will see the different options available in SQL server to fetch the column names.

    1) We can use the below query to get the column names.

    SELECT COLUMN_NAME
    FROM INFORMATION_SCHEMA.COLUMNS
    WHERE TABLE_NAME = 'Table Name'
    ORDER BY ORDINAL_POSITION
    

    'Table Name' needs to be replaced by the actual table name , for example if table name is Employee we need to modify the query as below:

    SELECT COLUMN_NAME
    FROM INFORMATION_SCHEMA.COLUMNS
    WHERE TABLE_NAME = 'Employee'
    ORDER BY ORDINAL_POSITION
    

    2) We can also use a System Stored Procedure sp_columns also and it will provide some additional information

    EXEC sp_columns 'Table Name'
    

    'Table Name' needs to be replaced by the actual table name , for example if table name is Employee we need to modify the query as below:

    EXEC sp_columns 'Employee'
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: