sql server 2008 - SQL get table columns with type name -


i have getting information of tables , columns below query.

is there handy way type name description nvarchar(20), numeric(14,2), varchar(max) etc. instead of lot's of case statements?

select      o.name tablename,     c.name columnname,     t.name +      case          when t.name '%char' '(' +              case                  when c.max_length = -1 'max'                  else convert(varchar(10), c.max_length / case when t.name 'n%' 2 else 1 end)              end + ')'         when t.name in ('numeric', 'decimal') '(' + convert(varchar(4), c.precision) + ',' + convert(varchar(4), c.scale) + ')'         -- when .... many other types         else ''     end typename      sys.objects o      inner join sys.columns c on o.object_id = c.object_id     inner join sys.types t on t.system_type_id = c.system_type_id , t.user_type_id = c.user_type_id     o.is_ms_shipped = 0 order     o.name,     c.column_id 

edit

sp_help nor information schema return name not being nvarchar(20), numeric(14,2), varchar(max)

i use view document database.... used , use data_type , length/precision

/****** object:  view [dbo].[vw_datadictionary]    script date: 17/07/2015 10:24:04 ******/ set ansi_nulls on go  set quoted_identifier on go  alter view [dbo].[vw_datadictionary] select     top (100) percent tb.name table_name, cast(ept.value nvarchar(200)) table_description, cast(c.name nvarchar(200)) column_name,                        cast(ep.value nvarchar(200)) column_description, t.name data_type, c.is_nullable is_null, object_definition(c.default_object_id) default_text,                        c.max_length length, c.precision numeric_precision, c.scale numeric_scale, c.column_id         sys.columns c left outer join                       sys.tables tb on tb.object_id = c.object_id left outer join                       sys.types t on c.system_type_id = t.system_type_id , c.user_type_id = t.user_type_id left outer join                       sys.extended_properties ept on ept.major_id = tb.object_id , ept.minor_id = 0 , ept.name = 'ms_description' left outer join                       sys.extended_properties ep on ep.major_id = c.object_id , ep.minor_id = c.column_id , ep.name = 'ms_description'     (tb.type = 'u') , (tb.name <> 'sysdiagrams') order table_name, c.column_id  go 

Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -