1. 程式人生 > >powerdesign逆向導如sql且生成name和註釋comment

powerdesign逆向導如sql且生成name和註釋comment

第一步:修改匯出SQL 開啟Power Designer ,選擇 Database->Edit Current DBMS…開啟對話方塊,找到Script->Objects->Table->SqlListQuery,開啟後修改value中的sql語句,修改結果如下:

{OWNER, TABLE, TABLE_TYPE, COMMENTS}
select
   t.owner,
   t.table_name,
   c.table_type,
   c.comments
from
   sys.all_all_tables t,
   sys.USER_TAB_COMMENTS c
where
   not exists (select 1 from sys.all_mviews s where s.owner = t.owner and t.table_name in (s.mview_name, s.update_log))
   and t.iot_name is null
   and nvl(t.dropped, 'NO') = 'NO'
   and t.table_name = c.table_name(+)
[  and t.table_name=%.q:TABLE%]
[  and t.owner=%.q:SCHEMA%]
order by
   t.owner, t.table_name

第二步:設定code不跟隨name改變

選擇選單中Tools->General Options…,在開啟的視窗中找到Dialog,去掉Name to Code mirroring 前面的勾,點選OK。

第三步:用指令碼將name設定成comments 選擇選單中Tools->Excute Commands -> Edit/Run Scripts… 在開啟的視窗中貼上如下指令碼,點選Run按鈕。

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