创 PowerDesigner 批量修改 批量删除 批量添加

参考
原文
这几天 使用了 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

  1. 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"

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值