1. 程式人生 > >決絕powerdesigner逆向工程生成PDM時,列註釋解決方案

決絕powerdesigner逆向工程生成PDM時,列註釋解決方案

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,內容如下:

  1. Option Explicit  
  2. ValidationMode = True
  3. InteractiveMode = im_Batch  
  4. Dim mdl 'the current model
  5. 'get the current active model
  6. Set mdl = ActiveModel  
  7. If (mdl IsNothingThen
  8. MsgBox "There is no current Model"
  9. ElseIfNot mdl.IsKindOf(PdPDM.cls_Model) Then
  10. MsgBox "The current model is not an Physical Data model."
  11. Else
  12. ProcessFolder mdl  
  13. EndIf
  14. 'This routine copy name into code for each table, each column and each view
  15. 'of the current folder
  16. Private sub ProcessFolder(folder)  
  17. Dim Tab 'running table
  18. for each Tab in folder.tables  
  19. if not tab.isShortcut then  
  20. if len(tab.comment) <> 0 then  
  21. tab.name = tab.comment  
  22. end if  
  23. OnErrorResumeNext
  24. Dim col 'running column
  25. for each col in tab.columns  
  26. if len(col.comment) <>0 then  
  27. col.name =col.comment  
  28. end if  
  29. OnErrorResumeNext
  30. next  
  31. end if  
  32. next  
  33. end sub  

在生成的PDM中,Powerdesigner介面-tools-Execute Cmmands-Edit/Run Scripts 在開啟的介面中,左上角,選擇開啟,Ctrl+O,選取剛才的 Comments2Name.vbs,並Run,效果同上。

邀月工作室

邀月工作室