1. 程式人生 > >Mysql 將表結構匯入 Powerdesigner ,並將註釋作為 name 列

Mysql 將表結構匯入 Powerdesigner ,並將註釋作為 name 列

步驟一:

安裝MYSQL的ODBC驅動

Connector/ODBC 5.1.10 下載地址:

選擇win-32 MIS安裝包,進行直接安裝就可以了。

步驟二:

配置OBDC驅動連線

步驟三:

 開啟PowerDesigner :

1)檔案->新建新模型

2)資料庫->connect to a Data Source

3)填寫資料庫連線資訊

4)開始逆向生成

確定後等待生成就好了。

可參考:http://blog.csdn.net/chamtianjiao/article/details/7258316


==========================================================================

將註釋和name列互相轉換如下:

在PowerDesigner中使用方法為:

   PowerDesigner->Tools->Execute Commands->Edit/Run Scripts

將程式碼Copy進去執行就可以了,是對整個CDM或PDM進行操作

[vb] view plain copy  print?
  1. '程式碼一:將Name中的字元COPY至Comment中
  2. Option   Explicit   
  3. ValidationMode   =   True
  4. InteractiveMode   =   im_Batch  
  5. Dim   mdl   
    '   the   current   model
  6. '   get   the   current   active   model 
  7. Set   mdl   =   ActiveModel   
  8. If   (mdl   IsNothing)   Then
  9.       MsgBox   "There   is   no   current   Model "
  10. ElseIfNot   mdl.IsKindOf(PdPDM.cls_Model)   Then
  11.       MsgBox   "The   current   model   is   not   an   Physical   Data   model. "
  12. Else
  13.       ProcessFolder   mdl   
  14. EndIf
  15. '   This   routine   copy   name   into   comment   for   each   table,   each   column   and   each   view 
  16. '   of   the   current   folder 
  17. Private   sub   ProcessFolder(folder)   
  18.       Dim   Tab   'running     table 
  19.       for   each   Tab   in   folder.tables   
  20.             if   not   tab.isShortcut   then   
  21.                   tab.comment   =   tab.name   
  22.                   Dim   col   '   running   column 
  23.                   for   each   col   in   tab.columns   
  24.                         col.comment=   col.name   
  25.                   next   
  26.             end   if   
  27.       next  
  28.       Dim   view   'running   view 
  29.       for   each   view   in   folder.Views   
  30.             if   not   view.isShortcut   then   
  31.                   view.comment   =   view.name   
  32.             end   if   
  33.       next  
  34.       '   go   into   the   sub-packages 
  35.       Dim   f   '   running   folder 
  36.       ForEach   f   In   folder.Packages   
  37.             if   not   f.IsShortcut   then   
  38.                   ProcessFolder   f   
  39.             end   if   
  40.       Next
  41. end   sub  


另外在使用REVERSE ENGINEER從資料庫反向生成PDM的時候,PDM中的表的NAME和CODE事實上都是CODE,為了把NAME替換為資料庫中Table或Column的中文Comment,可以使用以下指令碼:

[vb] view plain copy  print?在CODE上檢視程式碼片派生到我的程式碼片
  1. '程式碼二:將Comment中的字元COPY至Name中 
  2. Option   Explicit   
  3. ValidationMode   =   True
  4. InteractiveMode   =   im_Batch  
  5. Dim   mdl   '   the   current   model
  6. '   get   the   current   active   model 
  7. Set   mdl   =   ActiveModel   
  8. If   (mdl   IsNothing)   Then
  9.       MsgBox   "There   is   no   current   Model "
  10. ElseIfNot   mdl.IsKindOf(PdPDM.cls_Model)   Then
  11.       MsgBox   "The   current   model   is   not   an   Physical   Data   model. "
  12. Else
  13.       ProcessFolder   mdl   
  14. EndIf
  15. Private   sub   ProcessFolder(folder)   
  16. OnErrorResumeNext
  17.       Dim   Tab   'running     table 
  18.       for   each   Tab   in   folder.tables   
  19.             if   not   tab.isShortcut   then   
  20.                   tab.name   =   tab.comment  
  21.                   Dim   col   '   running   column 
  22.                   for   each   col   in   tab.columns   
  23.                   if col.comment="" then  
  24.                   else  
  25.                         col.name=   col.comment   
  26.                   end if  
  27.                   next   
  28.             end   if   
  29.       next  
  30.       Dim   view   'running   view 
  31.       for   each   view   in   folder.Views   
  32.             if   not   view.isShortcut   then   
  33.                   view.name   =   view.comment   
  34.             end   if   
  35.       next  
  36.       '   go   into   the   sub-packages 
  37.       Dim   f   '   running   folder 
  38.       ForEach   f   In   folder.Packages   
  39.             if   not   f.IsShortcut   then   
  40.                   ProcessFolder   f   
  41.             end   if   
  42.       Next
  43. end   sub