PowerDesigner實用技巧小結

一、ORACLE數據庫建模時,因爲ORACLE的表名、字段名若是是小寫會有必定的麻煩,須要將小寫轉化爲大寫?
(1)在打開pdm的狀況下,進入Tools-Model Options-Naming Convention,把Name和Code的標籤的Charcter case選項設置成Uppercase就能夠!
(2)若是僅想在preview這一層實現,也能夠選擇Database->Edit current database->Script->Sql->Format,有一項CaseSensitivityUsingQuote,它的 comment爲「Determines if the case sensitivity for identifiers is managed using double quotes」,表示是否適用雙引號來規定標識符的大小寫, 能夠看到右邊的values默認值爲「YES」,改成「No」便可!
建議使用方法(1)。
二、在PDM裏,發現某些字段的類型不可改?
這多是引用了DOMAIN的緣故,能夠雙擊此列,進行更改。
三、PDM鏈接的數據庫類型更改?
Database-Change/Edit Current Dbms...
四、PD中將Comment-Name拷貝VBS
在使用PowerDesigner對數據庫進行概念模型和物理模型設計時,通常在NAME或Comment中寫中文,在Code中寫英文。Name用來顯 示,Code在代碼中使用,但Comment中的文字會保存到數據庫Table或Column的Comment中,當Name已經存在的時候,再寫一次 Comment很麻煩,可使用如下代碼來解決這個問題:
代碼一:將Name中的字符COPY至Comment中sql

'****************************************************************************** 
'*   File:           name2comment.vbs 
'*   Purpose:     Database   generation   cannot   use   object   names   anymore   
'                         in   version   7   and   above. 
'                         It   always   uses   the   object   codes. 
' 
'                         In   case   the   object   codes   are   not   aligned   with   your   
'                         object   names   in   your   model,   this   script   will   copy   
'                         the   object   Name   onto   the   object   Comment   for   
'                         the   Tables   and   Columns. 
' 
'*   Title:         
'*   Version:     1.0 
'*   Company:     Sybase   Inc.   
'****************************************************************************** 
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 
                  tab.comment   =   tab.name 
                  Dim   col   '   running   column 
                  for   each   col   in   tab.columns 
                        col.comment=   col.name 
                  next 
            end   if 
      next 
      Dim   view   'running   view 
      for   each   view   in   folder.Views 
            if   not   view.isShortcut   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 
--------------------------------------------


         另外在使用REVERSE ENGINEER從數據庫反向生成PDM的時候,PDM中的表的NAME和CODE事實上都是CODE,爲了把NAME替換爲數據庫中Table或Column的中文Comment,可使用如下腳本:
代碼二:將Comment中的字符COPY至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 
-----------------------------------------------------------------------


以上兩段代碼都是VB腳本,在PowerDesigner中使用方法爲:
    PowerDesigner->Tools->Execute Commands->Edit/Run Scripts
將代碼Copy進去執行就能夠了,是對整個CDM或PDM進行操做
五、如何根據字段的中文NAME,以其漢語拼音首字母取得CODE英文名?
在tools--> execute command 下執行 run script 的VB腳本:
chn_to_ps.vbside

Option Explicit 
ValidationMode = True 
InteractiveMode = im_Batch 

' get the current active model 
Dim mdl ' the current model 
Set mdl = ActiveModel 
If (mdl Is Nothing) Then 
MsgBox "There is no Active Model" 
Else 
ListObjects(mdl) 
End If 

'----------------------------------------------------------------------------- 
' Sub procedure to scan current package and print information on objects from current package 
' and call again the same sub procedure on all children pacakge 
' of the current package 
'----------------------------------------------------------------------------- 
Private Sub ListObjects(fldr) '列出全部的對象 
output "Scanning " & fldr.code 
Dim obj ' running object 
For Each obj In fldr.children 
' Calling sub procedure to print out information on the object 
'DescribeObject obj 
TableSetNameToCode obj 
Next 

' go into the sub-packages 
Dim f ' running folder 
For Each f In fldr.Packages '遞歸調用列出全部的對象 
'calling sub procedure to scan children package 
ListObjects f 
Next 
End Sub 

'----------------------------------------------------------------------------- 
' Sub procedure to print information on current object in output 
'----------------------------------------------------------------------------- 
Private Sub DescribeObject(CurrentObject) 
if not CurrentObject.Iskindof(cls_NamedObject) then exit sub 
output "Found "+CurrentObject.ClassName+" """+CurrentObject.Name+""", Created by "+CurrentObject.Creator+" On "+Cstr(CurrentObject.CreationDate)   
End Sub 
'常數 值 描述 
'vbCr Chr(13) 回車符。 
'vbCrLf Chr(13) & Chr(10) 回車符與換行符。 
'vbFormFeed Chr(12) 換頁符;在 Microsoft Windows 中不適用。 
'vbLf Chr(10) 換行符。 
'vbNewLine Chr(13) & Chr(10) 或 Chr(10) 平臺指定的新行字符;適用於任何平臺。 
'vbNullChar Chr(0) 值爲 0 的字符。 
'vbNullString 值爲 0 的字符串 與零長度字符串 ("") 不一樣;用於調用外部過程。 
'vbTab Chr(9) 水平附籤。 
'vbVerticalTab Chr(11) 垂直附籤;在 Microsoft Windows 中不適用。 

Private Sub TableSetNameToCode(CurrentObject) 
if not CurrentObject.Iskindof(cls_Table) then exit sub 
'output "Found "+CurrentObject.ClassName+" """+CurrentObject.Name+""", Created by "+CurrentObject.Creator+" On "+Cstr(CurrentObject.CreationDate)   
    
if not CurrentObject.isShortcut then 
output CurrentObject.name 
CurrentObject.code = "T_"&GetPy( CurrentObject.name) 
CurrentObject.comment = CurrentObject.name & "_"&CurrentObject.code 
Dim col ' running column 
dim index1   
index1 = 0 
for each col in CurrentObject.columns 
dim str11 
str11 = GetPy( col.name)   
col.code = str11 & cstr(index1 ) 
col.Comment = col.name & "_" & col.code 
index1 = index1 + 1 
next 
end if   
    
End Sub 

'//生成漢字串首字母串 
function GetPy(strxx) 
dim i 
dim getpy1 
for i=1 to len(strxx) 
getpy1=getpy1 & getpychar(mid(strxx,i,1)) 

next 
output getpy1 
GetPy = getpy1 

End function 
'//獲取漢字的首字母 

function getpychar(char) 
'0---9 , a---z , A---Z 
if ((asc(char) >= asc("0") and asc(char) <= asc("9")) or (asc(char) >= asc("A") and asc(char) <= asc("Z")) or (asc(char) >= asc("a") and asc(char) <= asc("Z")) or asc(char) = asc("_") ) then 
getpychar = char 
else 
dim tmpp:tmpp=65536+asc(char) 
if(tmpp>=45217 and tmpp<=45252) then 
getpychar= "A" 
elseif(tmpp>=45253 and tmpp<=45760) then 
getpychar= "B" 
elseif(tmpp>=45761 and tmpp<=46317) then 
getpychar= "C" 
elseif(tmpp>=46318 and tmpp<=46825) then 
getpychar= "D" 
elseif(tmpp>=46826 and tmpp<=47009) then 
getpychar= "E" 
elseif(tmpp>=47010 and tmpp<=47296) then 
getpychar= "F" 
elseif(tmpp>=47297 and tmpp<=47613) then 
getpychar= "G" 
elseif(tmpp>=47614 and tmpp<=48118) then 
getpychar= "H" 
elseif(tmpp>=48119 and tmpp<=49061) then 
getpychar= "J" 
elseif(tmpp>=49062 and tmpp<=49323) then 
getpychar= "K" 
elseif(tmpp>=49324 and tmpp<=49895) then 
getpychar= "L" 
elseif(tmpp>=49896 and tmpp<=50370) then 
getpychar= "M" 
elseif(tmpp>=50371 and tmpp<=50613) then 
getpychar= "N" 
elseif(tmpp>=50614 and tmpp<=50621) then 
getpychar= "O" 
elseif(tmpp>=50622 and tmpp<=50905) then 
getpychar= "P" 
elseif(tmpp>=50906 and tmpp<=51386) then 
getpychar= "Q" 
elseif(tmpp>=51387 and tmpp<=51445) then 
getpychar= "R" 
elseif(tmpp>=51446 and tmpp<=52217) then 
getpychar= "S" 
elseif(tmpp>=52218 and tmpp<=52697) then 
getpychar= "T" 
elseif(tmpp>=52698 and tmpp<=52979) then 
getpychar= "W" 
elseif(tmpp>=52980 and tmpp<=53688) then 
getpychar= "X" 
elseif(tmpp>=53689 and tmpp<=54480) then 
getpychar= "Y" 
elseif(tmpp>=54481 and tmpp<=62289) then 
getpychar= "Z" 
else '若是不是中文,則用''代替 
getpychar="" 
end if 
end if 

output getpychar + "---->" + cstr(tmpp) 
End Function


注:能夠根據實際狀況須要,對腳本進行微調,如:根據名稱生成註釋等。
六、在查看編輯表時,能夠一次選中多個列,而後對選中列的字段類型、主鍵等統一操做。
七、邏輯圖形的顯示
Tools/Model Options選項能夠選擇圖形上是顯示Name、Code;
Tools/Display Preferences能夠選擇圖形上顯示的項目,如數據類型等;
八、在修改name的時候,code的值將跟着變更
Tools/General Options 打開Dialog將Operating modes中的 Name To Code mirroring 將前面的勾去掉
九、sql語句中表名與字段名前的引號去除
  也能夠選擇Database->Edit current database->Script->Sql->Format,有一項CaseSensitivityUsingQuote,它的 comment爲「Determines if the case sensitivity for identifiers is managed using double quotes」,表示是否適用雙引號來規定標識符的大小寫, 能夠看到右邊的values默認值爲「YES」,改成「No」便可!,建議使用這種方法

進入Tools-Model Options-Naming Convention,把Name和Code的標籤的Charcter case選項設置成Uppercase或者Lowercase,只要不是Mixed Case就行
十、批量生成測試數據
DataBase->Generation Test Data-> 在此項內,可自由選擇、設置
十一、根據中文名生成註釋(經過4修改一下也能夠,但效率過低)
cat Create_Comment_src_chn.vbs測試

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 code 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 
tab.comment = tab.name 
Dim col 'running column 
for each col in tab.columns 
col.comment= col.name 
next 
end if 
next 

Dim view 'running view 
for each view in folder.Views 
if not view.isShortcut 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


十二、PDM或CDM連線添加或刪除結點
CTRL+左鍵單擊便可。this

相關文章
相關標籤/搜索