使用PowerDesigner导出MySql数据库的表结构生成ER图

1、在PowerDesigner中新建模型。File ----New Model,在弹出的对话框中选择Physical Data Model类型,填写Model name后点击【OK】。



 2、点击“Database”->"Configure  Connections",弹出窗口“Configure Data Connections”, 并选择"Connection Profiles"如下图所示:



 3、新建mysql的链接,点击上图中的新建标识,弹出下图:



 如上图所示,连接类型为 JDBC,然后选择对应的数据库种类,填写连接数据库使用的用户名和密码,选择连接使用的驱动jar包。填写完毕后,可点击【Test Connection】测试连接数据库是否成功。

若返回 Connection test successful,则表明连接数据库成功,点击【OK】进入下一步。

注:连接数据库使用的jdk需是32位,64位时则连接不成功

4、连接成功后,点击“Database”->"Update Model from  Database(快捷键为:CTRL_R)",弹出窗口“Database Reverse Engineering Options”,



 如上图所示,点击左图中连接数据库按钮,弹出右侧图中的对话框,选择第3步中建立的数据库连接文件,点击【Connect】。

另外,若导出的数据量结构中需要导出外键等关系,则酌情选择如下选择项。

 

 5、选择之后,点击【确定】,则弹出如下图:

 如上图所示:可以选择某一个用户下的表,可以选择需要导出的数据表。

6、等选择合适之后,点击【OK】按钮,则弹出导出数据库表结构的动态进度表,如下图所示:

 

7、上一步进度完成之后,在PowerDesigner则显示导出的所有的数据表和表关系等,如下图所示:



 
如此,则将数据库的表结构导出来了,

8、在PowerDesigner中,表结构的code,name字段均为英文,不易阅读,若需要将备注中的字段替换到name字段显示,则执行方法:Tools -- Execute Commands -- Edit/Run Script ,则弹出如下图中的对话框:

将如下代码,放入输入框中,点击执行按钮或者【run】,执行之,

Vb 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 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.comment
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  
9、执行之后,则将备注中的字段填写到name字段了,如下图所示:

 
 完成。

猜你喜欢

转载自jiage17.iteye.com/blog/2199225