准备工作
1、PowerDesigner_16.5
2、mysql-connector-odbc-5.1.5-win32.msi
本次演示使用的是16.5版本的PowerDesigner,如果因为版本不兼容导致操作失败,可以尝试使用我这个版本,提供下载地址:
链接:https://pan.baidu.com/s/1ObWSzgGcebHCfZCbU89C-A 密码:rdia
odbc可以直接在网上搜索下载,也可以直接使用我提供的:
链接:https://pan.baidu.com/s/1yM_NitbEFTlW_tbBDtIyeA 密码:hc7s
一、开始逆向生成
1、使用管理员权限运行PowerDesigner,File(文件)==>Reverse Engineer(反转引擎)==>Database(数据库)
打开我们的New Physical Data Model(新建物理数据模型),Model name(模型名称)自己写,DBMS选择MySQL5.0,之后确定
2、打开Database Reverse Engineering Options(数据库反转引擎配置)
3、点击上图按钮,打开Connect to a Data Source(连接到一个数据源)
4、点击上图的Configure(配置)按钮,打开Configure Data Connections(配置数据连接)
5、点击上图Add Data Source(添加数据源)按钮,打开创建新数据源界面
选择第三个"系统数据源",下一步
选择MySQL ODBC 5.1 Driver,下一步
6、确认后打开数据库连接配置,除了前两项可随意填写,下面四项数据库相关的配置都要正确填写
7、Test通过之后,点击OK,回到我们的Configure Data Connections界面,就出现了我们刚刚配置的数据源,点击确定
8、回到我们的Connect to a Data Source(连接到一个数据源)界面,选择刚刚配置的数据源,之后点Connect(连接)
9、再次回到我们的Database Reverse Engineering Options(数据库反转引擎配置)界面,点击确定按钮
10、接着就打开了我们的Database Reverse Engineering(数据库反转引擎)界面,选择好数据库和表,点击OK按钮,即可实现数据库表的反转
二、生成内容配置
我们生成了数据之后,表格可能跟我们预期的不太一样,譬如name和code是一样的,对于那些在数据库表table中加了comment注释的来说,我们可以使用脚本将comment的信息覆盖掉name的内容:Tools(工具)==>Execute Commands(执行脚本)==>Edit/Run Script(编辑/运行脚本)
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 comment 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
tab.comment = tab.name
Dim col ' running column
for each col in tab.columns
col.comment= col.name
next
end if
next
Dim view 'running view
for each view in folder.Views
if not view.isShortcut then
view.comment = view.name
end if
next
' go into the sub-packages
Dim f ' running folder
For Each f In folder.Packages
if not f.IsShortcut then
ProcessFolder f
end if
Next
end sub
这里需要注意的是,PowerDesigner如果开启了name和code同步,会跟着把code名称替换了,我们不想把表名列名替换了,可以把同步关闭:Tools(工具)==>General Options(通用选项)==>Dialog(弹窗),将Name to Code mirroring取消勾选
最后,大家有什么不懂的或者其他需要交流的内容,也可以进入我的QQ讨论群一起讨论:654331206