查询数据库表或视图结构

select syscolumns.colid as 序号, syscolumns.name as 字段, sys.extended_properties.value as 字段说明,
case systypes.name
    when char then systypes.name+(+cast(syscolumns.length as varchar)+)
    when varchar then systypes.name+(+cast(syscolumns.length as varchar)+)when decimal then systypes.name+(+cast(syscolumns.xprec as varchar)+,+cast(syscolumns.xscale as varchar)+)when nchar then systypes.name+(+cast(syscolumns.length as varchar)+)
    when numeric then systypes.name+(+cast(syscolumns.xprec as varchar)+,+cast(syscolumns.xscale as varchar)+)
else
systypes.name
end as 数据类型,
case syscolumns.isnullable
when 0 then 非空
when 1 then end as 空/非空,
o.names
as 表名,
s.name
as 架构
from sys.objects as o
left join syscolumns on o.object_id = syscolumns.id
left join systypes on syscolumns.xtype = systypes.xtype
inner join sys.shcemas s on s.schema_id = 0.shecma_id
left join sys.extended_properties on o.object_id = sys.extended_properties.major_id and syscolumns.colid = sys.extended_properties.minor_id
where o.type=V‘ and systypes.status != ‘1‘

 

查询数据库表或视图结构

上一篇:sql常用语句


下一篇:springboot+Mybatis批量改foreach抛出java.sql.SQLSyntaxErrorException