Aug 25, 2011

How to select table column name and datatype in Ms Sql

 SELECT i_s.table_name
       AS
       [Table Name],
       i_s.column_name
       AS [Column Name],
       i_s.data_type
       AS [Data Type],
       Isnull(Isnull(i_s.character_maximum_length, i_s.numeric_precision), '')
       AS
       [Max Length],
       Isnull(s.VALUE, '')
       AS DESCRIPTION
FROM   information_schema.columns AS i_s
       LEFT OUTER JOIN sys.extended_properties AS s
         ON s.major_id = Object_id(i_s.table_schema + '.' + i_s.table_name)
            AND s.minor_id = i_s.ordinal_position
            AND s.name = 'MS_Description'
WHERE  ( Objectproperty(Object_id(i_s.table_schema + '.' + i_s.table_name),
                'IsMsShipped'
         ) = 0 )
       AND ( i_s.table_name = 'v_QTW_EMPProfile' )
ORDER  BY [Table Name],
          i_s.ordinal_position
 

No comments:

Post a Comment

What is the use of n-tier architecture and 3-tier architecture?

how to implement 3-tier architecture in asp.net using c#. 3-Tier architecture is also called layered architecture. Some people called it ...