1. 当一个SQL数据库中存在多个库时,扫描数据表字段

'数据库名称' db_name,
'数据库所在IP' ip,
d.name table_name,  
a.colorder column_order,a.name column_name,
(case when COLUMNPROPERTY( a.id,a.name,'IsIdentity')=1 then '是'else '' end) is_id_entity, 
(case when (SELECT count(*) FROM sysobjects  
WHERE (name in (SELECT name FROM sysindexes  
WHERE (id = a.id) AND (indid in  
(SELECT indid FROM sysindexkeys  
WHERE (id = a.id) AND (colid in  
(SELECT colid FROM syscolumns WHERE (id = a.id) AND (name = a.name)))))))  
AND (xtype = 'PK'))>0 then '是' else '' end) is_pk,b.name data_type,a.length length,  
COLUMNPROPERTY(a.id,a.name,'PRECISION') as numeric_scale,  
isnull(COLUMNPROPERTY(a.id,a.name,'Scale'),0) as numeric_precision,(case when a.isnullable=1 then '是'else '' end) is_null,  
CONVERT(nvarchar(50),isnull(e.text,' ')) column_default,CONVERT(nvarchar(200),isnull(g.[value], ' ')) AS remarks
FROM  syscolumns a 
left join systypes b on a.xtype=b.xusertype  
inner join sysobjects d on a.id=d.id and d.xtype='U' and d.name<>'dtproperties' 
left join syscomments e on a.cdefault=e.id  
left join sys.extended_properties g on a.id=g.major_id AND a.colid=g.minor_id
left join sys.extended_properties f on d.id=f.class and f.minor_id=0
where b.name is not null 

and d.name = 'acct_cash_flow'
order by a.id,a.colorder


©️2020 CSDN 皮肤主题: 程序猿惹谁了 设计师:上身试试 返回首页