Columns for a particular table in a database in SQL Server

In order to find the columns for a particular table in a database in SQL Server, use the below query in the corresponding database:

SELECT
    COLUMN_NAME
  , ORDINAL_POSITION
  , COLUMN_DEFAULT 
  , IS_NULLABLE 
  , DATA_TYPE 
  , CHARACTER_MAXIMUM_LENGTH 
  , COLLATION_NAME 
FROM
INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME ='TableName'
ORDER BY ORDINAL_POSITION

This query gives the details of all the colums in a table (replace the TableName in the above query with the table name that you want to retrieve the data)

Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: