PowerDesigner使用方法小結


PowerDesigner多用來進行數據庫模型設計,具有SQL語句自動生成等功能。當然,也有不少缺點,比如團隊分享。

一、設置PowerDesigner模型視圖中數據表顯示列

1、Tools-Display Preference…

2、窗口左邊Category中General Settings下選擇Table

3、窗口右邊Advanced…

4、窗口左邊選擇Columns

5、窗口右邊List columns中,選擇要顯示的列

image

 

二、設置PowerDesigner設計表時,自動將name列值中的一部分復制到code列

1、把name/code自動復制功能打開。默認是打開的。

Tool-Genneral-Options Dialog-Name to Code mirroring

2、Tools->Model Options....->Naming Convention
3、選中Name,並勾選Enable name/code conversions.
4、選擇Name To Code

粘貼腳本代碼

腳本1:
.set_value(_First, true, new)
.foreach_part(%Name%, "'#'")
.if (%_First%)
.delete(%CurrentPart%)
.enddelete
.set_value(_First, false, update)
.else
%CurrentPart%
.endif
.next
這個例子是把Name內容的#號后邊的內容當作Code.
 
腳本2:
.set_value(_First, true, new)
.foreach_part(%Name%, "'#'")
.if (%_First%)
%CurrentPart%
.set_value(_First, false, update)
.endif
.next
 這個例子是把Name內容的#號前邊的內容當作Code.

 

三、從數據庫導入數據到PowerDesigner中后,將comment列值復制到name列

運行腳本 Tools->Execute Commands->Edit/Run Scripts(Ctrl Shift X)

'******************************************************************************
'* File:     comment2name.vbs
'* Purpose:  在PowerDesigner的PDM圖形窗口中顯示數據列的中文注釋
'* Title:    將字段的comment賦值到字段的name中
'* Category: 打開物理模型,運行本腳本(Ctrl+Shift+X)
'* Copyright:foxzz@163.com,2006/07/25 .
'* Author:   foxzz
'* Created:  
'* Modified: 
'* Version:  1.0
'* Comment:  遍歷物理模型中的所有表,將字段的comment賦值到字段的name中。
'            在將name置換為comment過程中,需要考慮的問題
'            1、name必須唯一,而comment有可能不唯一。
'               處理辦法是如果字段的comment重復,則字段的name=comment+1、2、3...
'            2、comment值有可能為空,這種情況下對字段的name不處理。
'               針對oracle數據庫,將comment on column 字段名稱 is '';添加到C:/pdcomment.txt文件中。
'               在補充comment完畢后,便於在數據庫中執行        
'******************************************************************************

Option Explicit 
ValidationMode = True 
InteractiveMode = im_Batch

Dim system, file
Set system = CreateObject("Scripting.FileSystemObject")
Dim ForReading, ForWriting, ForAppending   '打開文件選項
ForReading   = 1 ' 只讀 
ForWriting   = 2 ' 可寫 
ForAppending = 8 ' 可寫並追加
'打開文本文件
Set file = system.OpenTextFile("C:/pdcomment.txt", ForWriting, true)


'判斷當前model是否物理數據模型
Dim mdl
Set mdl = ActiveModel 
If (mdl Is Nothing) Then 
   MsgBox "處理對象無模型" 
ElseIf Not mdl.IsKindOf(PdPDM.cls_Model) Then 
   MsgBox "當前模型不是物理數據模型" 
Else 
   ProcessFolder mdl,file 
End If 
file.Close


'******************************************************************************
Private sub ProcessFolder(folder,file)

Dim i,j,k
i=0:j=0:k=0

'列數組,記錄字段里不重復的comment
Dim ColumnComment() 
Dim ColumnCommentNumber()
ReDim Preserve ColumnComment(i)
ReDim Preserve ColumnCommentNumber(i)

Dim tbl   '當前表
Dim col   '當前字段 
dim curComment  '當前字段comment

'處理模型中的表
for each tbl in folder.tables 
    if not tbl.isShortcut then 
       if len(trim(tbl.comment))<>0 then
          '可以在這里顯示table的comment
          'tbl.name = tbl.name+"("+trim(tbl.comment)+")"
       end if  

       '處理表中的列
       for each col in tbl.columns 
           k = 0
           curComment = trim(col.comment)
           if len(curComment)<>0 then
              '遍歷相異的comment數組
              for j = 0 to i
                  if ColumnComment(j) = curComment then
                     '如果找到相同的comment,則相關計數器加1
                     ColumnCommentNumber(j) = ColumnCommentNumber(j) + 1
                     k = j
                  end if 
              Next
              '如果沒有相同的comment,則k=0,此時ColumnCommentNumber(0)也為0
              '否則ColumnCommentNumber(k)不為0
              if ColumnCommentNumber(k) <> 0 then
                 col.name = curComment & cstr(ColumnCommentNumber(k))
              else
                 col.name  = curComment
                 'ColumnComment(0)、ColumnCommentNumber(0)永遠為空
                 '將相異的comment記錄添加到數組中
                 i = i + 1
                 ReDim Preserve ColumnComment(i)
                 ReDim Preserve ColumnCommentNumber(i)
                 ColumnComment(i) = curComment
                 ColumnCommentNumber(i) = 0
              end if
           else
              '寫入文件中
              file.WriteLine "comment on column "+ tbl.name+"."+col.code+" is '';"           
           end if
       next 
    end if 
    '由於不同表的name允許相同,因此此時重新初始化。
    '因為ColumnComment(0)、ColumnCommentNumber(0)為空,可以保留
    ReDim Preserve ColumnComment(0)
    ReDim Preserve ColumnCommentNumber(0)
    i=0:j=0:k=0

next

Dim view  '當前視圖
for each view in folder.Views 
    if not view.isShortcut then 
       '可以在這里顯示view的comment
       'view.name =  view.comment
    end if 
next

'對子目錄進行遞歸
Dim subpackage 'folder
For Each subpackage In folder.Packages 
    if not subpackage.IsShortcut then 
       ProcessFolder subpackage , file
    end if 
Next

end sub

 

四、將name列值復制到comment列

運行腳本 Tools->Execute Commands->Edit/Run Scripts(Ctrl Shift X)

'把pd中那么name想自動添加到comment里面
'如果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 

' 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

 

參考:

1、PowerDesigner中Table視圖同時顯示Code和Name http://blog.csdn.net/downmoon/article/details/8108968

2、PowerDesigner Name/Code自動調整(轉) http://hi.baidu.com/jonik/item/7d39588c3dda708e4514cf76

3、在PowerDesigner的PDM圖形窗口中顯示數據列的中文注釋 http://blog.csdn.net/zengzhe/article/details/974205

4、powerDesigner 把name項添加到注釋(comment),完美方案! http://www.cnblogs.com/dukey/archive/2010/01/20/dukey.html

- by 一個農夫 -


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM