zoukankan      html  css  js  c++  java
  • SQL2008 获取数据库全部表结构

    SELECT
    表名= d.name, --case when a.colorder=1 then d.name else '' end,
    表说明= ST.TABLE_NAME_CN,--case when a.colorder=1 then isnull(ST.TABLE_NAME_CN,'') else '' end,
    字段序号=a.colorder,
    字段名=a.name,
    是否种子标识=case when COLUMNPROPERTY( a.id,a.name,'IsIdentity')=1 then 'yes'else '' end,
    主键=case when exists(SELECT 1 FROM sysobjects where xtype='PK' and parent_obj=a.id and name in (
    SELECT name FROM sysindexes WHERE indid in(
    SELECT indid FROM sysindexkeys WHERE id = a.id AND colid=a.colid
    ))) then 'yes' else '' end,
    类型=b.name,
    设置的字节数=a.length,
    长度=COLUMNPROPERTY(a.id,a.name,'PRECISION'),
    小数位数=isnull(COLUMNPROPERTY(a.id,a.name,'Scale'),0),
    允许空=case when a.isnullable=1 then 'yes'else '' end,
    默认值=isnull(e.text,''),
    字段说明=isnull(g.FIELD_NAME_CN,'')
    FROM syscolumns a
    left join systypes b on a.xusertype=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 SB_FIELD G ON a.name = g.FIELD_NAME AND d.name = g.TABLE_NAME
    LEFT JOIN SB_TABLE st ON st.TABLE_NAME = D.name
    --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.major_id AND f.minor_id=0
    WHERE isnull(st.TABLE_NAME_CN,'') <> '' --d.name='表名' --如果只查询指定表,加上此条件
    order by a.id,a.colorder

  • 相关阅读:
    mysql 分列或取子串
    Excel “20200504”文本格式转化为时间格式
    Mysql清空数据表
    python 做词云图
    Pandas操作excel
    python中zip()函数的用法
    Excel技能提升
    JS 学习笔记
    元类理解与元类编程 《Python3网络爬虫开发》中第九章代理的使用代码Crawler中代码的理解
    关于选择器注意的点
  • 原文地址:https://www.cnblogs.com/rayz/p/2557160.html
Copyright © 2011-2022 走看看