在使用PowerDesigner做物理模型设计时,name一般会表示字段说明, code表示列明, 导致生成的DML语句中comment为空, 可以使用以下代码来解决这个问题:
将Name中的字符复制至Comment中
OptionExplicit
ValidationMode=True
InteractiveMode=im_BatchDimmdl'thecurrentmodel'getthecurrentactivemodel
Setmdl=ActiveModel
If(mdlIsNothing)Then
MsgBox"ThereisnocurrentModel "
ElseIfNotmdl.IsKindOf(PdPDM.cls_Model)Then
MsgBox"ThecurrentmodelisnotanPhysicalDatamodel. "
Else
ProcessFoldermdl
EndIf'Thisroutinecopynameintocommentforeachtable,eachcolumnandeachview
'ofthecurrentfolder
PrivatesubProcessFolder(folder)
DimTab'runningtable
foreachTabinfolder.tables
ifnottab.isShortcutthen
tab.comment=tab.name
Dimcol'runningcolumn
foreachcolintab.columns
col.comment=col.name
next
endif
nextDimview'runningview
foreachviewinfolder.Views
ifnotview.isShortcutthen
view.comment=view.name
endif
next'gointothesub-packages
Dimf'runningfolder
ForEachfInfolder.Packages
ifnotf.IsShortcutthen
ProcessFolderf
endif
Next
endsub
另外在使用REVERSE ENGINEER从数据库反向生成PDM的时候,PDM中的表的name和code事实上都是code,为了把name替换为数据库中Table或Column的中文Comment,可以使用以下脚本:
将Comment中的字符复制至Name中
OptionExplicit
ValidationMode=True
InteractiveMode=im_BatchDimmdl'thecurrentmodel'getthecurrentactivemodel
Setmdl=ActiveModel
If(mdlIsNothing)Then
MsgBox"ThereisnocurrentModel "
ElseIfNotmdl.IsKindOf(PdPDM.cls_Model)Then
MsgBox"ThecurrentmodelisnotanPhysicalDatamodel. "
Else
ProcessFoldermdl
EndIfPrivatesubProcessFolder(folder)
On Error Resume Next
DimTab'runningtable
foreachTabinfolder.tables
ifnottab.isShortcutthen
tab.name=tab.comment
Dimcol'runningcolumn
foreachcolintab.columns
if col.comment="" then
else
col.name=col.comment
end if
next
endif
nextDimview'runningview
foreachviewinfolder.Views
ifnotview.isShortcutthen
view.name=view.comment
endif
next'gointothesub-packages
Dimf'runningfolder
ForEachfInfolder.Packages
ifnotf.IsShortcutthen
ProcessFolderf
endif
Next
endsub
【PowerDesigner name与comment互转】脚本执行方式:
Tools->Execute Commands->Edit/Run Scripts
文章图片
PowerDesigner中默认不显示comment, 可以设置显示:
1.
Tools->Display Preferences...
文章图片
2.应用到所有表
文章图片