決絕powerdesigner逆向工程生成PDM時,列註釋解決方案
阿新 • • 發佈:2019-02-18
1、建立DBMS
Powerdesigner界 面-tools-Resources-DBMS,點選左上角的New,選擇copy from templete,如果你的資料庫是sql server 2005,選擇系統自帶的SQL server 2005,如果是sql server 2008,選擇系統自帶的sqlsv2k8.xdb。本例中是sql server 2008 r2,故選擇 sqlsv2k8.xdb,起一個新名字,如 SQL2008_Mod_201105。
2、建立資料來源,逆向生成測試,順利成功!
此時再生成資料庫指令碼時,會自動將Comment中的中文註釋帶入到指令碼中。
美中不足的是Name還是英文
有兩個解決辦法:
3-1、改進指令碼
Powerdesigner介面-Database-Edit Current DBMS
如下: (本文以sql server 2008為例,sql server 2005類同。 )
將表的Name換為Comment
將列的Name換為Comment
此時生成的效果最為理想。
3-2、利用vbs指令碼完成。
在Sybase安裝路徑/VB Scripts 下新建Comments2Name.vbs,內容如下:
- Option Explicit
- ValidationMode = True
-
InteractiveMode = im_Batch
- Dim mdl 'the current model
- 'get the current active model
- Set mdl = ActiveModel
- If (mdl IsNothing) Then
- MsgBox "There is no current Model"
- ElseIfNot mdl.IsKindOf(PdPDM.cls_Model) Then
- MsgBox "The current model is not an Physical Data model."
- Else
- ProcessFolder mdl
- EndIf
-
'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
- OnErrorResumeNext
- Dim col 'running column
- for each col in tab.columns
- if len(col.comment) <>0 then
- col.name =col.comment
- end if
- OnErrorResumeNext
- next
- end if
- next
- end sub
在生成的PDM中,Powerdesigner介面-tools-Execute Cmmands-Edit/Run Scripts 在開啟的介面中,左上角,選擇開啟,Ctrl+O,選取剛才的 Comments2Name.vbs,並Run,效果同上。