最近有把项目数据库转换为数据模型的需要,其实之前做过多次,有点忘了,重新找了资料,整理一下,其中部分是从网上找的资源,写一下是为了方便自己后续查找
前提:使用powerdesigner工具,mysql数据库
一。建立数据连接
1.首先新建一个“PhysicalDataModel”类型的文件,然后点击“Database”->"Configure Connections",弹出窗口“Configure Data Connections”, 并选择"Connection Profiles"如下图所示:
输入相关信息,ip,端口,数据库名,用户名,密码,最后选ok
点击确定
点击确定,即可生成对应的pdm模型
注意:若Power Designer找不到所选择的jar包或jar包不在CLASSPATH环境变量所指定的路径,将会报错:
Non SQL Error: Could not load class oracle.jdbc.OracleDriver。
解决办法请参考一下地址:
地址一: http://ema100.blog.sohu.com/281187861.html?qq-pf-to=pcqq.c2c
地址二: http://www.blogjava.net/amigoxie/archive/2013/10/13/404925.html
2.添加name列
Tools-->Display Perference-->选中左侧 “Table” ,再在右侧选中“Advanced”,进入“Customize Content”,选中“Columns”,选右上方的放大镜标志(搜索标志)--> "select Attributes"中选中code,并移动到最顶层,保存,发现就有了id和name列
3.转换code为comments,
ctrl+shift+x弹出窗口,输入如下脚本,或者保存到对应的目录下面,每次使用不用再查(脚本是借鉴别人的,很久以前保存的,忘了链接)
脚本内容如下:
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
Private sub ProcessFolder(folder)
On Error Resume Next
Dim Tab 'running table
for each Tab in folder.tables
if not tab.isShortcut then
tab.name = tab.comment
Dim col ' running column
for each col in tab.columns
ifcol.comment="" then
else
col.name= col.comment
endif
next
end if
next
Dim view 'running view
for each view in folder.Views
if not view.isShortcut then
view.name = view.comment
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