PowerDesigner 表名、字段大小写转换

面对不同的数据库大小写规范,一个个字段修改太麻烦了,如果使用了PowerDesigner设计,有比较简单的方法。进入PowerDesigner,打开一个PDM,在菜单栏找到:Tools – Excute Commands – Edit/Run Script,或者直接按Ctrl+Shift+X调出脚本执行窗口,输入下边的代码就可以了。使用的是VBScript,语义比较容易理解,可以根据自己的需求修改。

打开模型 Tools-->Execute Commands --> Edit/Run Script

UCase大写 LCase小写

输入以下语句(根据实际情况可做相应调整)

Option Explicit
ValidationMode = True
InteractiveMode = im_Batch

Dim mdl ' the current model

' 取得当前Model
Set mdl = ActiveModel
If (mdl Is Nothing) Then
<wbr><wbr> MsgBox "There is no current Model"</wbr></wbr>
ElseIf Not mdl.IsKindOf(PdPDM.cls_Model) Then
<wbr><wbr> MsgBox "The current model is not an Physical Data model."</wbr></wbr>
Else
<wbr><wbr> ProcessFolder mdl</wbr></wbr>
End If

Private sub ProcessFolder(folder)
<wbr><wbr><wbr> '处理表</wbr></wbr></wbr>
<wbr><wbr> Dim Tab</wbr></wbr>
<wbr><wbr> for each Tab in folder.tables</wbr></wbr>
<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr> tab.code = UCase(tab.code)</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr> '修改字段名</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr> Dim col</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr> for each col in tab.columns</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr> col.code= UCase(col.code)</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr> next</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr> '修改索引名</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr> Dim idx</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr> for each idx in tab.indexes</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr> idx.code= UCase(idx.code)</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr> next</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr> '修改主键名</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr> Dim key</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr> for each key in tab.keys</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr> key.code= UCase(key.code)</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr> next</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr> next</wbr></wbr>

' 同理处理视图
' Dim view
'<wbr><wbr> for each view in folder.Views</wbr></wbr>
<wbr><wbr> '<wbr><wbr> if not view.isShortcut then</wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr><wbr> ' view.code = view.name</wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr> ' end if</wbr></wbr></wbr>
' next

<wbr><wbr> ' go into the sub-packages</wbr></wbr>
<wbr><wbr> Dim f ' running folder</wbr></wbr>
<wbr><wbr> For Each f In folder.Packages</wbr></wbr>
<wbr><wbr><wbr><wbr><wbr> if not f.IsShortcut then</wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr> ProcessFolder f</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr> end if</wbr></wbr></wbr></wbr></wbr>
<wbr><wbr> Next</wbr></wbr>
end sub

你可能感兴趣的:(powerDesigner)