数据库建模(PowerDesigner)将所有表同一个字段统一设置字段属性

    在大型系统建模时,同一字段存在多个表中,有时需将这个字段的属性设为一致,一个一个表去设麻烦也有可能漏掉,我们可以写一段VBS代码统一修改,如下是为“IsDelete”字段统一 1.必填 2.默认值0

Tools->Execute Commands->Edit/Run Script 弹出窗 将如下代码贴入 点击 Run 即可

Option Explicit
ValidationMode = True
InteractiveMode = im_Batch

'ceaate by runnerrunning 

' get the current active model
Dim mdl ' the current model
dim TestDataObj 
Set mdl = ActiveModel
If (mdl Is Nothing) Then
   MsgBox "There is no Active Model"
Else
   ListObjects(mdl)
End If


'-----------------------------------------------------------------------------
Private Sub ListObjects(fldr) '列出所有的对象
   output "Scanning " & fldr.code
   Dim obj ' running object
   
   For Each obj In fldr.children
      ' Calling sub procedure to print out information on the object
      
      TableSetComment obj
   Next

   		' go into the sub-packages
   Dim f ' running folder
   For Each f In fldr.Packages '递归调用列出所有的对象
      'calling sub procedure to scan children package
      ListObjects f
   Next
End Sub


Private Sub TableSetComment(CurrentObject)
   
   
   if not CurrentObject.Iskindof(cls_Table) then exit sub
   'output "Found "+CurrentObject.ClassName+" """+CurrentObject.Name+""", Created by "+CurrentObject.Creator+" On "+Cstr(CurrentObject.CreationDate)   
   'output "Found "+CurrentObject.ClassName+" ; "+CurrentObject.Name
      
      if not CurrentObject.isShortcut then
         'CurrentObject.Comment = CurrentObject.name &vbCrLf& CurrentObject.Comment
         Dim col  ' running column
         Dim num
         
         for each col in CurrentObject.columns
            if col.Code="IsDelete"  then
               output CurrentObject.Name
                  col.Mandatory=1
                  col.DefaultValueDisplayed=0
            end if
            
         next
         
         
      end if      
End Sub

 

你可能感兴趣的:(PowerDesigner,PowerDesigner)