Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

description of columns in a table

Status
Not open for further replies.

rk68

Programmer
Jul 15, 2003
171
IN
Hi,
How can I get the description of each columns of a table in MS SQL.

TIA,
Raj
 
What exactly do you mean by description? Do you mean the datatypes of the columns? If so try something like:
Code:
SELECT 
    DB_NAME() AS DatabaseName, 
    T.[name] AS Table_Name, 
    AC.[name] AS Column_Name, 
    AC.column_id AS Ordinal_Position, 
    TY.[name] AS Data_type, 
    CASE WHEN AC.[precision] = 0 THEN AC.max_length ELSE AC.[precision] END AS CLength, 
    OBJECT_DEFINITION(AC.default_object_id) AS Column_Default 
    ,AC.is_identity 
    ,AC.is_nullable
FROM sys.tables            T 
INNER JOIN sys.all_columns AC ON T.[object_id] = AC.[object_id] 
INNER JOIN sys.types       TY ON AC.[system_type_id] = TY.[system_type_id] 
                                AND AC.[user_type_id] = TY.[user_type_id] 
WHERE T.[is_ms_shipped] = 0 
    AND T.[name] IN ('MyTable1', 'MyTable2')
ORDER BY DatabaseName, Table_Name, Ordinal_Position;



djj
The Lord is my shepherd (Psalm 23) - I need someone to lead me!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top