Navicat Premium快速导出数据库ER图和数据字典

Posted Blogger

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Navicat Premium快速导出数据库ER图和数据字典相关的知识,希望对你有一定的参考价值。

2.快速导出数据库数据字典:

SQL Server 数据库,生成数据字典

use YourDatabase  --指定要生成数据字典的数据库
go

SELECT  
表名=case when a.colorder=1 then d.name else \'\' end, 
表说明=case when a.colorder=1 then isnull(f.value,\'\') else \'\' end,
字段序号=a.colorder, 
字段名=a.name, 
标识=case when COLUMNPROPERTY(a.id,a.name,\'IsIdentity\')=1 then \'\'else \'\' end, 
主键=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 = a.id AND colid=a.colid 
   ))) then \'\' 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 \'\'else \'\' end, 
默认值=isnull(e.text,\'\'), 
字段说明=isnull(g.[value],\'\') 
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.major_id and f.minor_id =0 
--where d.name=\'要查询的表\' --如果只查询指定表,加上此条件   
order by a.id,a.colorder

或者将表头赋值放在后面:

 

-- 数据字典
SELECT
    (CASE
        WHEN a.colorder = 1 THEN d.name
        ELSE \'\'
    END) 表名
   ,a.colorder 字段序号
   ,a.name 字段名
   ,(CASE
        WHEN COLUMNPROPERTY(a.id, a.name, \'IsIdentity\') = 1 THEN \'\'
        ELSE \'\'
    END) 标识
   ,(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) 主键
   ,b.name 类型
   ,a.length 占用字节数
   ,COLUMNPROPERTY(a.id, a.name, \'PRECISION\') AS 长度
   ,ISNULL(COLUMNPROPERTY(a.id, a.name, \'Scale\'), 0) AS 小数位数
   ,(CASE
        WHEN a.isnullable = 1 THEN \'\'
        ELSE \'\'
    END) 允许空
   ,ISNULL(e.text, \'\') 默认值
   ,ISNULL(g.[value], \'\') AS 字段说明
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.major_id
ORDER BY a.id, a.colorder

 

 

 

接下来将数据字典导出:

首先,点击右上角的导出

然后,选择导出格式:

选择导出的地址和输入文件的名称

 

 参考:https://www.idaima.com/article/3083

mysql,生成数据字典

USE information_schema;

SELECT
    T.TABLE_SCHEMA AS \'数据库名称\',
    T.TABLE_NAME AS \'表名\',
    T.TABLE_TYPE AS \'表类型\',
    T. ENGINE AS \'数据库引擎\',
    C.ORDINAL_POSITION AS \'字段编号\',
    C.COLUMN_NAME AS \'字段名\',
    C.COLUMN_TYPE AS \'数据类型\',
    C.IS_NULLABLE AS \'允许为空\',
    C.COLUMN_KEY AS \'键类型\',
    C.EXTRA AS \'自增属性\',
    C.CHARACTER_SET_NAME AS \'编码名称\',
    C.COLUMN_COMMENT AS \'字段说明\'
FROM
    COLUMNS C
INNER JOIN TABLES T ON C.TABLE_SCHEMA = T.TABLE_SCHEMA
AND C.TABLE_NAME = T.TABLE_NAME
WHERE
    T.TABLE_SCHEMA = \'mysql\'  --指定要生成数据字典的数据库

参考:http://www.jianshu.com/p/f491d0d3c503

 

以上是关于Navicat Premium快速导出数据库ER图和数据字典的主要内容,如果未能解决你的问题,请参考以下文章

Navicat查看并导出ER图

使用Navicat生成ER关系图并导出

navicat premium怎么用

使用Navicat+Premium模型设计表之间关系图(1:n;n:n)

navicat premium没有简化sql的功能么

Navicat Premium 15 生成E-R图并导出