--SQL查询每个表的字段数量select b.[name], count(*) As AllCount,ISNULL(ISNULL(sum(case when isnullable=0 then 1 end),null),null) as NotNullCountfrom syscolumns aINNER JOIN( select [id], [name] from [sysobjects] where [type] = 'u' ) AS b ON a.id = b.[id] GROUP b
由于项目前后用了2个数据库,需要统计数据库结构的变化,需要统计每个表的变化,由于人工核对挺浪费时间,就写了一点代码: 1.统计表的字段数量(查询表有多少列): select count(name) from syscolumns where id=object_id('表名') eg:select count(name) from syscolumns where id=object_id('t_dk') 2.查询数据库字段名 (表有哪些字段) select name from 数据