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添加共用字段和自动添加注释的方法结束了。

posted on 2014-08-16 11:30  星小野  阅读(10664)  评论(0编辑  收藏  举报