PowerDesigner导入SQL脚本生成带中文注释(comment)的ER图并保存为图片格式(含通用可执行vb脚本文件)
目录
1、安装数据库建模工具PowerDesigner 16.5
数据库建模工具PowerDesigner 16.5的安装、汉化与扩展教程请参考:
数据库建模工具PowerDesigner 16.5的安装、汉化与扩展教程(超详细)_蓝多多的小仓库的博客-CSDN博客
2、打开 PowerDesigner,选择反向工程
点击菜单 File
------>Reverse Engineer
------>Database
3、选择数据库类型
Model name:数据库模型的名称
DBMS:数据库管理系统,下拉选择数据库类型
4、导入SQL脚本文件并生成数据库表模型
选择使用脚本文件,点击 Add Files
图标,选择需要导入的本地 SQL 脚本文件并导入
到此,我们可以看到刚刚选择好的需要导入的 SQL 脚本文件列表,如果还需要选择,可重复步骤4;如果没有,点确定即可开始反向工程生成数据库表模型。
5、去掉Diagram画板黑色网格线(选做)
点击工具栏的 Tools ------> Display Preferences 菜单项,在弹出来的 Display Preferences 界面中找到 General Settings ------> General ------> Diagram,然后取消勾选 “Show page delimiter” 选项,最后 OK 确定保存,即可。如图所示:
6、ER图常规显示(包含是否为Null及表名注释)
Tools------>Display Preferences------>table,这里你需要显示什么就勾选即可。(注意:表名注释需要预先在sql语句中写出哦,例如:COMMENT ON TABLE "you_table" IS '你的表';)
7、显示中文注释comment(含vb可执行脚本)
1>先多选一列code(用于改为注释),步骤:Tools------>Display Preferences------>table------>Advances------>columns------>select------>勾选code------>OK------>确定
2> 通过脚本修改表名注释,字段注释
Tools------>Execute Commands------>Edit/Run Script...
3>在弹框中输入代码并run
Option Explicit ValidationMode = True InteractiveMode = im_Batch Dim mdl 'the current model 'get the current active model Set mdl = ActiveModel If (mdl Is Nothing) Then MsgBox "There is no current Model" ElseIf Not mdl.IsKindOf(PdPDM.cls_Model) Then MsgBox "The current model is not an Physical Data model." Else ProcessFolder mdl End If 'This routine copy name into code for each table, each column and each view 'of the current folder Private sub ProcessFolder(folder) Dim Tab 'running table for each Tab in folder.tables if not tab.isShortcut then if len(tab.comment) <> 0 then tab.name = tab.name 'tab.name = tab.comment&"["&tab.name&"]" end if On Error Resume Next Dim col 'running column for each col in tab.columns if len(col.comment) <>0 then col.name =col.comment end if On Error Resume Next next end if next end sub
4>到此,我们就可以看到ER图中有中文注释这一列啦
8、将生成的ER图保存为图片
Ctrl+A 将图表全部选中,点击Edit------>Export Image在保存类型中选择JPEG或PNG即可