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)

Advertisements
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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s

  • Recent Posts

    • 450,719 hits
  • Join 37 other followers

  • Archives

  • Categories

  • June 2011
    M T W T F S S
    « May   Jul »
     12345
    6789101112
    13141516171819
    20212223242526
    27282930  
  • Advertisements
%d bloggers like this: