1. 程式人生 > >PowerDesigner經驗——從sql生成pdm(name欄位值為sql中的comment描述值)

PowerDesigner經驗——從sql生成pdm(name欄位值為sql中的comment描述值)

從已有的sql生成pdm的過程如下:

1、如圖點選:

2、選擇sql匹配的資料庫:


3、點選確定後,在彈出的對話方塊中新增sql指令碼:


4、點選確定後,就會生成表:

5、剛生產的pdm表中的name欄位和code欄位值是一致的,要想name欄位為sql中的comment欄位描述一致,需要如下操作:

點選 【Tools】-【Execute Commands】-【Run Script


6、在Edit/Run Script編輯框中輸入VB指令碼:


VB指令碼語句如下:

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 
if len(tab.comment) <> 0 then 
tab.name = tab.comment 
end if 
On Error Resume Next 
Dim col 'running column 
for each col in tab.columns 
if len(col.comment) <>0 then 

col.name =col.comment 
end if 
On Error Resume Next 
next 
end if 
next 
end sub

7、點選【Run】按鈕,後就可以看到表中的name欄位值為sql中的comment註釋的值了。