PowerDesigner 使用小結

  這裏總結一篇關於數據建模工具 PowerDesigner 的使用小技巧,下面列出的兩個應用場景要在網上現找解決方案的話還真不必定好找,因此選擇將這兩個棘手的問題先記下來。數據庫

1. PDM 中表間關係出現多引用狀況

  這種狀況通常是在由 LDM 生成 PDM 時,對於一對一聯繫,沒有指定主從表關係,如圖:工具

  

  致使生成的 PDM 中出現一對一關係出現兩個引用:spa

  

    若是指定了 Dominant role ,則只會產生一個引用:code

  

  

2. 去外鍵問題

  默認狀況下,經過 PDM 生成數據庫初始化腳本時會帶有外鍵生成腳本,以下:blog

  若是在 PDM 的關係屬性中將 Generate 後面的鉤去掉則可解決(話說這個問題還卡了蠻長時間,最後是一個老工程師指點的)ip

  

3. 在 PDM 中將字段命名格式改爲下劃線分隔形式

  須要進行操做: Tools -> Excute Commands -> Edit/Run Script , 以下圖:ci

  

  選擇執行腳本文件: ToLowerCase.vbs :get

  

  

  最後點擊 Run 便可,點完不會有任何彈窗予以提示,可直接點擊 PDM 中的表查看。這裏將 ToLoweCase.vbs 中的代碼共享一下:input

Option Explicit
ValidationMode = True
InteractiveMode = im_Batch

Dim mdl ' the current model
Dim i

' 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 Function ToLowerCase(input)
  Dim result, ch, prevIsUpper
  result = ""
  For i = 1 to Len(input)
    ch = Mid(input, i, 1)
    If Asc(ch) < 91 And Asc(ch) > 64 Then
      If i > 1 And Not prevIsUpper Then
        result = result + "_"        
      End If
      result = result + LCase(ch)
      prevIsUpper = True
    Else
      result = result + ch
      prevIsUpper = False
    End If
  Next
  ToLowerCase = result
End Function

' This routine copies the name into code for each table, column and view
' of the current folder
Private sub ProcessFolder(folder)
   Dim Tab 'running  table
   Dim rc 'return code

   for each Tab in folder.tables
      if not tab.isShortcut then         
         tab.Code = ToLowerCase(tab.Code)
         'output ToLowerCase(tab.Code)
         Dim col ' running column
         for each col in tab.columns            
            col.Code = ToLowerCase(col.Code)
            'output ToLowerCase(col.Code)
         next
      end if
   next
end sub
相關文章
相關標籤/搜索