PowerDesigner使用方法小結

來源:互聯網
上載者:User

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

一、設定PowerDesigner模型視圖中資料表顯示列

1、Tools-Display Preference…

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

3、視窗右邊Advanced…

4、視窗左邊選擇Columns

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

 

二、設定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_BatchDim system, fileSet 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 mdlSet 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,ki=0:j=0:k=0'列數組,記錄欄位裡不重複的commentDim 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=0nextDim view  '當前視圖for each view in folder.Views     if not view.isShortcut then        '可以在這裡顯示view的comment       'view.name =  view.comment    end if next'對子目錄進行遞迴Dim subpackage 'folderFor Each subpackage In folder.Packages     if not subpackage.IsShortcut then        ProcessFolder subpackage , file    end if Nextend 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 一個農夫 -

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.