天天看點

powerdesigner連接配接mysql生成pdm,及常用腳本使用

本文主要介紹三節内容:

1.安裝odbc驅動——用于powerdesigner連接配接mysql

2.資料庫生成模型

3.腳本的使用,如:如何将name拷貝給comment

4.如何顯示原字段,并修改顯示順序

一:下載下傳odbc驅動并進行安裝

1.先檢視mysql版本:

用戶端:select version(); select @@version;

dos或linux:mysql -V;mysql --help |grep Distrib;status;select version(); select @@version;

2.選擇合适的odbc版本,比如我的mysql大版本為5.6,仍可下載下傳5.3.13的odbc插件。

直通車:https://dev.mysql.com/downloads/connector/odbc/5.3.html

無論PC是32位作業系統,還是64位,均可安裝32位版本odbc。

3.安裝

直接next–>finish

powerdesigner連接配接mysql生成pdm,及常用腳本使用
powerdesigner連接配接mysql生成pdm,及常用腳本使用

4.odbcad32.exe添加資料源

A.直接左下角開始處搜尋odbc,點選彈出配置界面。

powerdesigner連接配接mysql生成pdm,及常用腳本使用
powerdesigner連接配接mysql生成pdm,及常用腳本使用

點選test,若成功點選OK。配置成功後顯示如下圖所示。

powerdesigner連接配接mysql生成pdm,及常用腳本使用

**

二.資料庫生成模型

**

打開PowerDesigner軟體,進行導入生成模型

A、選擇菜單,導入資料源

powerdesigner連接配接mysql生成pdm,及常用腳本使用

B.選擇資料庫版本

powerdesigner連接配接mysql生成pdm,及常用腳本使用

C.點選添加odbc驅動

powerdesigner連接配接mysql生成pdm,及常用腳本使用
powerdesigner連接配接mysql生成pdm,及常用腳本使用

D.選中需要生成pdm的表,點選OK後即可生成資料庫模型

powerdesigner連接配接mysql生成pdm,及常用腳本使用
powerdesigner連接配接mysql生成pdm,及常用腳本使用

三.使用vbs腳本對模型進行添加comment的操作

powerdesigner連接配接mysql生成pdm,及常用腳本使用
powerdesigner連接配接mysql生成pdm,及常用腳本使用
powerdesigner連接配接mysql生成pdm,及常用腳本使用

腳本一:顯示備注資訊

Option   Explicit   
    ValidationMode   =   True   
    InteractiveMode   =   im_Batch
    Dim blankStr
    blankStr   =   Space(1)
    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  
      
    Private   sub   ProcessFolder(folder)   
    On Error Resume Next  
          Dim   Tab   'running     table   
          for   each   Tab   in   folder.tables   
                if   not   tab.isShortcut   then   
                      tab.name   =   tab.comment  
                      Dim   col   '   running   column   
                      for   each   col   in   tab.columns   
                      if col.comment = "" or replace(col.comment," ", "")="" Then
                            col.name = blankStr
                            blankStr = blankStr & Space(1)
                      else  
                            col.name = col.comment   
                      end if  
                      next   
                end   if   
          next  
      
          Dim   view   'running   view   
          for   each   view   in   folder.Views   
                if   not   view.isShortcut   then   
                      view.name   =   view.comment   
                end   if   
          next  
      
          '   go   into   the   sub-packages   
          Dim   f   '   running   folder   
          For   Each   f   In   folder.Packages   
                if   not   f.IsShortcut   then   
                      ProcessFolder   f   
                end   if   
          Next   
    end   sub
           

腳本二:Name轉到Comment注釋字段

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   comment   for   each   table,   each   column   and   each   view 
'   of   the   current   folder 
Private   sub   ProcessFolder(folder)    
      Dim   Tab   'running     table    
      for   each   Tab   in   folder.tables    
            if   not   tab.isShortcut then
                     if  trim(tab.comment)="" then'如果有表的注釋,則不改變它.如果沒有表注釋.則把name添加到注釋裡面.
                        tab.comment   =   tab.name
                     end if  
                  Dim   col   '   running   column    
                  for   each   col   in   tab.columns   
                        if trim(col.comment)="" then '如果col的comment為空,則填入name,如果已有注釋,則不添加;這樣可以避免已有注釋丢失.
                           col.comment=   col.name   
                        end if 
                  next    
            end   if    
      next    
  
      Dim   view   'running   view    
      for   each   view   in   folder.Views    
            if   not   view.isShortcut and trim(view.comment)=""  then    
                  view.comment   =   view.name    
            end   if    
      next    
  
      '   go   into   the   sub-packages    
      Dim   f   '   running   folder    
      For   Each   f   In   folder.Packages    
            if   not   f.IsShortcut   then    
                  ProcessFolder   f    
            end   if    
      Next    
end   sub
           

腳本三:Comment注釋字段轉到Name

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    
  
Private   sub   ProcessFolder(folder)    
On Error Resume Next   
      Dim   Tab   'running     table    
      for   each   Tab   in   folder.tables    
            if   not   tab.isShortcut   then    
                  tab.name   =   tab.comment   
                  Dim   col   '   running   column    
                  for   each   col   in   tab.columns    
                  if col.comment="" then   
                  else  
                        col.name=   col.comment    
                  end if  
                  next    
            end   if    
      next    
  
      Dim   view   'running   view    
      for   each   view   in   folder.Views    
            if   not   view.isShortcut   then    
                  view.name   =   view.comment    
            end   if    
      next    
  
      '   go   into   the   sub-packages    
      Dim   f   '   running   folder    
      For   Each   f   In   folder.Packages    
            if   not   f.IsShortcut   then    
                  ProcessFolder   f    
            end   if    
      Next    
end   sub
           

腳本四:字段都轉到大寫的

Option Explicit
ValidationMode = True
InteractiveMode = im_Batch
Dim mdl 
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

Private sub ProcessFolder(folder)
 Dim Tab
 for each Tab in folder.tables
   tab.code = UCase(tab.code)
   Dim col
   for each col in tab.columns
    col.code= UCase(col.code)
   next
   Dim idx
   for each idx in tab.indexes
    idx.code= UCase(idx.code)
   next
   Dim key
   for each key in tab.keys
    key.code= UCase(key.code)
   next
 next
 Dim f  
 For Each f In folder.Packages
  if not f.IsShortcut then
   ProcessFolder f
  end if
 Next
end sub
           

四.顯示原字段,并修改字段順序

A.顯示原字段

powerdesigner連接配接mysql生成pdm,及常用腳本使用
powerdesigner連接配接mysql生成pdm,及常用腳本使用
powerdesigner連接配接mysql生成pdm,及常用腳本使用
powerdesigner連接配接mysql生成pdm,及常用腳本使用
powerdesigner連接配接mysql生成pdm,及常用腳本使用

B.修改字段順序

powerdesigner連接配接mysql生成pdm,及常用腳本使用

參考:https://www.cnblogs.com/xmyjcs/p/8536233.html