How do I find the data types such as xml or text or image of a specified table?

Published 18 July 07 07:34 AM | SQL Master 

 

USE <database_name>;
GO
SELECT name AS column_name
    ,column_id
    ,TYPE_NAME(user_type_id) AS type_name
    ,max_length
    ,CASE
       WHEN max_length = -1 AND TYPE_NAME(user_type_id) <> 'xml'
            THEN 1
            ELSE 0
     END AS [(max)]
FROM sys.columns
WHERE object_id=OBJECT_ID('<schema_name.table_name>')
    AND ( TYPE_NAME(user_type_id) IN ('xml','text', 'ntext','image')
         OR (TYPE_NAME(user_type_id) IN ('varchar','nvarchar','varbinary')
         AND max_length = -1)
        );
GO

(extracted from BOL)

Filed under: , , , , ,

Comments

# SSQA.net - SqlServer-QA.net said on July 23, 2007 6:17 PM:

USE &lt;database_name&gt;; GO SELECT name AS column_name ,column_id ,TYPE_NAME(user_type_id) AS type_name

Anonymous comments are disabled

About SQL Master

**__________________________________** SQL Server MVP, Sr. DBA & industry expert. - Knowledge is of two kinds. We know a subject ourselves or we know where we can find information on it. It is also a power and you will gain by sharing it.