tools - execute commands - edit/ run Scripe 打開窗口輸入vb腳本命令
2.1.統一添加默認字段:
對于需要排除在外的表,可添加在下面代碼中: if instr(",Ex1,Ex2,",","+CurrentObject.Code+",")>0 then exit sub
Option Explicit
ValidationMode =True
InteractiveMode = im_BatchDim mdl
Set mdl = ActiveModel
If(mdl IsNothing)ThenMsgBox "There is no Active Model"ElseListObjects(mdl)EndIfPrivateSub ListObjects(fldr)output"Scanning "& fldr.codeDim obj For Each obj In fldr.childrenTableSetComment objNextDim f For Each f In fldr.Packages ListObjects fNextEndSubPrivateSub TableSetComment(CurrentObject)ifnot CurrentObject.Iskindof(cls_Table)thenexitsubif instr(",Ex1,Ex2,",","+CurrentObject.Code+",")>0thenexitsubifnot CurrentObject.isShortcut thenDim col Dim numdim create_user_iddim create_timedim update_user_iddim update_timedim is_deletecreate_user_id=1update_user_id=1create_time=1update_time=1is_delete=1for each col in CurrentObject.columnsnum= num +1if col.Code="create_user_id"thencreate_user_id=100endifif col.Code="create_time"thencreate_time=100endifif col.Code="update_user_id"thenupdate_user_id=100endifif col.Code="update_time"thenupdate_time=100endifif col.Code="is_delete"thenis_delete=100endifnextif create_user_id=1then CurrentObject.columns.CreateNewAt(num)for each col in CurrentObject.columns if col.DataType=""then col.Name="創建人"col.Code="create_user_id"col.Comment="創建人"col.DataType="varchar(64)"col.Mandatory=1endifnextnum=num+1endifif create_time=1then CurrentObject.columns.CreateNewAt(num)for each col in CurrentObject.columns if col.DataType=""then col.Name="創建時間"col.Code="create_time"col.Comment="創建時間"col.DataType="datetime"col.DefaultValue="CURRENT_TIMESTAMP"endifnextnum=num+1endifif update_user_id=1then CurrentObject.columns.CreateNewAt(num)for each col in CurrentObject.columns if col.DataType=""then col.Name="修改人"col.Code="update_user_id"col.Comment="修改人"col.DataType="varchar(64)"endifnextnum=num+1endifif update_time=1then CurrentObject.columns.CreateNewAt(num)for each col in CurrentObject.columns if col.DataType=""then col.Name="修改時間"col.Code="update_time"col.Comment="修改時間"col.DataType="datetime"col.DefaultValue="CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"endifnextnum=num+1endifif is_delete=1then CurrentObject.columns.CreateNewAt(num)for each col in CurrentObject.columns if col.DataType=""then col.Name="刪除標志"col.Code="is_delete"col.Comment="刪除標志"col.DataType="tinyint"col.DefaultValue="0"endifnextnum=num+1endifendifEndSub
2.2.統一刪除字段:
對于需要排除在外的表,可添加在下面代碼中: if instr(",Ex1,Ex2,",","+tab.Code+",")=0 then
Option Explicit
ValidationMode =True
InteractiveMode = im_BatchDim mdl Set mdl = ActiveModel
If(mdl IsNothing)Then
MsgBox "There is no current Model"ElseIfNot mdl.IsKindOf(PdPDM.cls_Model)Then
MsgBox "The current model is not an Physical Data model."Else
ProcessFolder mdl
EndIfPrivatesub ProcessFolder(CurrentObject)DimTabfor eachTabin CurrentObject.tablesif instr(",Ex1,Ex2,",","+tab.Code+",")=0thenifnottab.isShortcut thenDim col for each col intab.columnsif instr(col.code,"update_user_id")<>0thencol.Deleteendifif instr(col.code,"update_time")<>0thencol.Deleteendifif instr(col.code,"create_user_id")<>0thencol.Deleteendifif instr(col.code,"create_time")<>0thencol.Deleteendifnextendifendifnext
MsgBox "success"endsub
2.3.統一修改表名稱:
Option Explicit
ValidationMode =True
InteractiveMode = im_BatchDim mdl Set mdl = ActiveModel
If(mdl IsNothing)Then
MsgBox "There is no current Model"ElseIfNot mdl.IsKindOf(PdPDM.cls_Model)Then
MsgBox "The current model is not an Physical Data model."ElseProcessFolder mdl
EndIfPrivatesub ProcessFolder(CurrentObject)DimTabDim NameStr , CodeStrfor eachTabin CurrentObject.tables Tab.name= Replace(Tab.name,"ori_name","new_name")Tab.code = Replace(Tab.code ,"s_","student_")nextMsgBox "success"endsub
2.4. 統一修改字段屬性:
對于需要排除在外的表,可添加在下面代碼中: if instr(",Ex1,Ex2,",","+tab.Code+",")=0 then
dim model set model = ActiveModel
If(model IsNothing)ThenMsgBox "There is no current Model"ElseIfNot model.IsKindOf(PdPDM.cls_Model)ThenMsgBox "The current model is not an Physical Data model."ElseProcessTables modelProcessSequences modelMsgBox "success"EndIfsub ProcessSequences(folder)dim sequencefor each sequence in folder.sequencessequence.name=LCase(sequence.name)sequence.code =LCase(sequence.code)nextendsubsub ProcessTables(folder)dim tablefor each table in folder.tablesif instr(",Ex1,Ex2,",","+table.Code+",")=0thenifnot table.IsShortCut then ProcessTable tableendifendifnextdim subFolderfor each subFolder in folder.PackagesProcessTables subFoldernextendsubsub ProcessTable(table)dim colfor each col in table.Columnsif col.code ="s_name"then col.code ="student_name" col.DataType ="vachar(64)"col.DefaultValue="1"col.Mandatory=0endifcol.code =LCase(col.code)col.name=LCase(col.name)next table.name=UCase(table.name)table.code =UCase(table.code)endsub
對于其他需要修改的屬性,可在ProcessTable方法中自定義編輯代碼
2.5.其他函數
在2.4.中將ProcessTables subFolder調用的方法替換為下述方法即可
表字段的部分替換:
sub ReplaceCol(table)dim colfor each col in table.Columnsif instr(col.code,qty)>0then col.code = Replace(col.code,"qty","quantity")endifif instr(col.code,amt)>0then col.code = Replace(col.code,"amt","amount")endifnextendsub