参考
原文
这几天 使用了 PowerDesigner 来 整理表结构,分享下。
下面,我们 通过 VBScript脚本 实现了 excel导入表字段、批量修改表前缀、批量添加表字段、批量添加表字段。
执行脚本:
ctrl + shift + x 打开运行VBS 代码窗口,粘贴脚本后,运行
1.excel 导入 PowerDesigner
2.PowerDesigner 批量修改表前缀
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
'of the current folder
Private sub ProcessFolder(folder)
Dim Tab 'running table
Dim NameStr , CodeStr
for each Tab in folder.tables
'修改 Tab.name 与 Tab,code
Tab.name = Replace( Tab.name , "OLD_" , "NEW_")
Tab.code = Replace( Tab.code , "OLD_" , "NEW_")
next
end sub
- PowerDesigner 批量删除表字段
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
'of the current folder
Private sub ProcessFolder(folder)
Dim Tab 'running table
for each Tab in folder.tables
if not tab.isShortcut then
Dim col 'running column
for each col in tab.columns
'删除公共字段字段 by Sinu
if instr(col.code,"CJR")<>0 then
col.Delete
end if
if instr(col.code,"CJSJ")<>0 then
col.Delete
end if
if instr(col.code,"XGR")<>0 then
col.Delete
end if
if instr(col.code,"XGSJ")<>0 then
col.Delete
end if
next
end if
next
MsgBox "success"
end sub
4 PowerDesigner 批量添加表字段
Option Explicit
Dim mdl ' the current model
Set mdl = ActiveModel
Dim Tab 'running table
Dim col_1
Dim col_2
Dim col_3
Dim col_4
' 定义属性变量
for each Tab in ActiveModel.Tables
Set col_1 = Tab.Columns.CreateNew
Set col_2 = Tab.Columns.CreateNew
Set col_3 = Tab.Columns.CreateNew
Set col_4 = Tab.Columns.CreateNew
'添加公共字段 by Sinu
col_1.name = "创建人"
col_1.code = "CJR"
col_1.DataType = "varchar(50)"
col_1.comment= "创建人"
col_2.name = "创建时间"
col_2.code = "CJSJ"
col_2.DataType = "datetime"
col_2.comment= "创建时间"
col_3.name = "修改人"
col_3.code = "XGR"
col_3.DataType = "varchar(50)"
col_3.comment= "修改人"
col_4.name = "修改时间"
col_4.code = "XGSJ"
col_4.DataType = "datetime"
col_4.comment= "修改时间"
next
MsgBox "success"