• 获取SQLServer的最完整数据字典的SQL语句


    获取SQLServer 的最完整数据字典

    以下代码在Microsoft SQL Server 2013中执行通过

    SELECT
    
    sysobjects.name AS 表名称 ,
    --sys.extended_properties.[value] AS 表说明 ,
    syscolumns.name AS 字段名称 ,
    --properties.[value] AS 字段说明 ,
    systypes.name AS 字段类型 ,
    syscolumns.length AS 字段长度 ,
    ISNULL(COLUMNPROPERTY(syscolumns.id, syscolumns.name,'Scale'), 0) AS 小数位数 ,
    
    CASE WHEN syscolumns.isnullable=0
     THEN ''
    ELSE ''
    END AS 是否为空 ,
    CASE WHEN syscomments.text IS NULL
     THEN '' ELSE syscomments.text
    END AS 缺省值 ,
    CASE WHEN COLUMNPROPERTY(syscolumns.id, syscolumns.name, 'IsIdentity')= 1
     THEN '' ELSE ''
    END AS 递增字段 ,
    CASE WHEN sysindexes.name IS NULL
     THEN ''
    ELSE sysindexes.name
    END AS 索引名称 ,
    CASE WHEN sysindexkeys.keyno IS NULL
     THEN ''
    ELSE CONVERT(VARCHAR(10),sysindexkeys.keyno )
    END AS 索引位置 ,
    CASE WHEN sysindexes.indid=1
     THEN ' 聚集索引 '
    WHEN sysindexes.indid>1 AND sysindexes.indid<>255
     THEN ' 非聚集索引 '
    WHEN sysindexes.indid IS NULL
     THEN ''
    ELSE
     ' 其他 '
    END AS 索引类型 ,
    CASE WHEN EXISTS
    (SELECT 1
      FROM sysobjects
     WHERE xtype = 'PK' AND name IN
     (SELECT name
        FROM sysindexes
       WHERE indid IN
       (SELECT indid
          FROM sysindexkeys
         WHERE id = syscolumns.id AND colid = syscolumns.colid)))
     THEN '' ELSE ''
    END AS 主键 ,
    CASE WHEN sysforeignkeys.constid IS NULL
     THEN ''
    ELSE ''
    END AS 外健
    FROM syscolumns                            -- 数据表字段
    INNER JOIN sysobjects                        -- 数据对象
      ON sysobjects.id = syscolumns.id
    INNER JOIN systypes                         -- 数据类型
      ON syscolumns.xtype = systypes.xtype
    LEFT OUTER JOIN sys.extended_properties properties       -- 字段属性信息
      ON syscolumns.id = properties.Minor_id
     AND syscolumns.colid = properties.Minor_id
    LEFT OUTER JOIN sys.extended_properties                -- 表属性信息
      ON sysobjects.id = sys.extended_properties.Minor_id
     AND sys.extended_properties.Minor_id = 0
    LEFT OUTER JOIN syscomments                -- 注释信息
      ON syscolumns.cdefault = syscomments.id
    LEFT OUTER JOIN sysindexkeys                -- 索引中的键或列的信息
      ON sysindexkeys.id = syscolumns.id
     AND sysindexkeys.colid = syscolumns.colid
    LEFT OUTER JOIN sysindexes                  -- 数据库 索引表
      ON sysindexes.id = sysindexkeys.id
     AND sysindexes.indid = sysindexkeys.indid
    LEFT OUTER JOIN sysforeignkeys
      ON sysforeignkeys.fkeyid = syscolumns.id
     AND sysforeignkeys.fkey = syscolumns.colid
    WHERE (sysobjects.xtype = 'U')
    order by sysobjects.id,syscolumns.colid

    转载于 http://blog.csdn.net/baoqiangwang/article/details/4695361

  • 相关阅读:
    Python自动化测试框架有哪些?
    Python正则表达式
    用户事务处理中同步请求与异步请求区别
    Python——数据结构—链表
    Mysql的隔离级别 以及对脏读、不可重复读、幻读的理解
    http协议及与https协议的区别
    Cookie与Session的区别
    Python——数据结构—数组
    Python—Flask写项目Mysql显示sqlalchemy.exc.OperationalError: (_mysql_exceptions.OperationalError) (1038, 'Out of sort memory, consider increasing server sort buffer size')
    Python—将PyCharm中的代码提交在Gitee码云的方法
  • 原文地址:https://www.cnblogs.com/cumulonimbus/p/5638684.html
Copyright © 2020-2023  润新知