sqlserver 查询表字段类型

使用下面的SQL语句可以查询,SQLSERVER数据库表有哪些字段以及数据类型是什么
select column_name,
       case when NUMERIC_PRECISION is not null and (data_type='decimal' or data_type='numeric') then
                data_type+'('+cast(NUMERIC_PRECISION as varchar)+','+cast(NUMERIC_SCALE as varchar)+')'
            when  CHARACTER_MAXIMUM_LENGTH is not null then
                data_type+'('+cast(CHARACTER_MAXIMUM_LENGTH as varchar)+')'
            else
                data_type
       end as data_type,
       case when column_default IS null then ''
            else
              'DEFAULT  '+replace( replace(column_default,'(',''), ')','')
       end as defalutvalue,
       case when is_nullable='YES' then ''
            else 'NOT NULL'
       end as is_nullable
 from information_schema.columns
where table_name = 'AccountRecord'


你可能感兴趣的:(SQLSERVER)