下面是一個更新(騙人貨!)的GalacticCowboy's answer解決一些問題,並更新所有的(我認爲)的SQL Server 2008個R2數據類型:
select data_type +
case
when data_type like '%text' or data_type in ('image', 'sql_variant' ,'xml')
then ''
when data_type in ('float')
then '(' + cast(coalesce(numeric_precision, 18) as varchar(11)) + ')'
when data_type in ('datetime2', 'datetimeoffset', 'time')
then '(' + cast(coalesce(datetime_precision, 7) as varchar(11)) + ')'
when data_type in ('decimal', 'numeric')
then '(' + cast(coalesce(numeric_precision, 18) as varchar(11)) + ',' + cast(coalesce(numeric_scale, 0) as varchar(11)) + ')'
when (data_type like '%binary' or data_type like '%char') and character_maximum_length = -1
then '(max)'
when character_maximum_length is not null
then '(' + cast(character_maximum_length as varchar(11)) + ')'
else ''
end as CONDENSED_TYPE
, *
from information_schema.columns
order by table_schema, table_name, ordinal_position
我不是真的想要整個表的腳本。我試圖在生成的XQuery中包含可解析的數據類型 – 2008-10-31 12:39:32