PowerDesigner批量添加索引、修改索引

 PowerDesigner批量添加索引、修改索引

使用方式:

打开需要操作的pdm,然后按快捷键:ctrl + shift +x

拷贝以下代码,点击Run(F5), 开始递归目录,稍等片刻弹出提示及完成操作。

命名格式:

索引:IDX_TableName_序号

 

 

'******************************************************************************
'* File:     Add_Index.vbs
'* Purpose:  为主键添加索引,或修改索引名称,ctrl+shift+x 粘贴代码点击运行
'* Title:    索引格式: IDX_<表名>_序号
'* Category: 
'* Version:  1.0
'* Company:  Sybase Inc. 
'******************************************************************************
 
Option Explicit
 
'
' get the current active model
'
Dim mdl ' the current model
Set mdl = ActiveModel
If (mdl Is Nothing) Then
   MsgBox "There is no Active Model"
End If
Dim fldr,line
Set Fldr = ActiveDiagram.Parent
 
 
ListObjects(fldr)
MsgBox "处理完成,请在PDM中查看"
 
 
Private Sub ListObjects(fldr)
   Dim tab,tab2 ' running object
   For Each tab In fldr.tables
     output "Found "+tab.ClassName+" "+tab.Name
     '删除以前的所有索引
      Dim inx
      for each inx in tab.indexes
         inx.Delete()
      next 
      line  = 1
      '遍历每一行,如果是主键就添加索引
      Dim col,col2
      for each col in tab.columns
        if col.primary =true then
           '为主键添加索引
            AddIndex  tab,col,line
            line = line + 1
        else 
            '为外键添加索引,没有建立外键关联,只是字段名称相同
              For Each tab2 In fldr.tables
                  for each col2 in tab2.columns
                      if col2.primary =true and col2.Code=col.Code then
                        AddIndex  tab,col,line
                        line = line + 1
                      end if
                  Next
              Next
        end if
         
      next
   Next
   
End Sub
'
' 为表的某一列增加索引
'
Private Sub AddIndex(table,column,line)
      Dim newIndex,newIndexCol
      set newIndex = table.Indexes.CreateNew()
      set newIndexCol = newIndex.IndexColumns.CreateNew()
      newIndexCol.column = column
      newIndex.Name = "IDX_"&table.Code&"_"&Cstr(line)
      newIndex.Code = newIndex.Name
End Sub

'
' 统一修改索引名字
'
Private Sub ChangeIndexName(table)
      Dim inx,line
      line  = 1
      for each inx in table.Indexes
       inx.Name= "IDX_"&table.Code&"_"&Cstr(line)
       inx.Code= inx.Name
       line = line + 1
      next 
End Sub

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值