PowerDesigner 如何添加每個表中共用的字段及自動添加注釋


PowerDesigner 如何添加每個表中共用的字段:

  有時候在創建表的時候會有一些共用的字段,但是每一張表都要去創建,這樣做很麻煩,特別是這樣重復的工作,稍不留意就會出現問題,實際上在PD中有這樣一種方法幫我們省去這樣繁瑣重復的工作。

  1>.選中一張表,點擊屬性,打開Columns.

  2>.點擊Add Columns(Ctrl+Add),然后選擇共用的字段,點擊確定,OK,煩惱結束。(Point:這樣做還是新增了共用的字段,並不是和其它的表進行關聯),如圖:

  

 

  我在建模的時候,希望在生成腳本的時候有注釋,所以才會看到Comment列,實際上,只要你的表中的Name列不為空,運行下面的VBScript,PD會幫你自動填充注釋的Comment列值。

  
'把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
View Code

  打開運行腳本的界面(Crtl+Shift+X),輸入腳本,運行后注釋的值就會自動的幫你填充好。

  到此,PD添加共用字段和自動添加注釋的方法結束了。


免責聲明!

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



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