天天看點

sql腳本PowerDesigner生成資料庫文檔準備sql腳本(純潔的腳本)sql腳本逆向生成pdm注解轉表name生成模闆生成文檔

最近項目總結,需要用PowerDesigner生成一下資料庫文檔,遇到了一個小問題記錄一下整個生成過程

準備sql腳本(純潔的腳本)

Navicat導出腳本

不允許保留字段

1.    varchar字段

            `phone` varchar(20) CHARACTER SETutf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '聯系方式',

2.    datetime 字段

            `create_time` datetime(0)NOT NULL DEFAULT CURRENT_TIMESTAMPCOMMENT '建立時間',

       `update_time` datetime(0) NOT NULL DEFAULTCURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP(0) COMMENT '更新時間',

可以保留字段

1.    每個字段可以定義NOT NUL DEFAULT 0DEFAULT ''

不可保留表資訊(留下commemt就好了)

CREATETABLE `demo` (`id` bigint(20) NOT NULL AUTO_INCREMENT) ENGINE = InnoDB AUTO_INCREMENT =23 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '示範資訊'ROW_FORMAT = Compact;

sql腳本逆向生成pdm

Pd -> 工具欄-> File ->Reverse Engineer  -> database -> 選擇 mysql5.0

sql腳本PowerDesigner生成資料庫文檔準備sql腳本(純潔的腳本)sql腳本逆向生成pdm注解轉表name生成模闆生成文檔

注解轉表name

1.  這裡比較重要解決後期遇到的問題

2. Pd中 -> 工具欄-> tools  -> execute commands -> edit/run script  

sql腳本PowerDesigner生成資料庫文檔準備sql腳本(純潔的腳本)sql腳本逆向生成pdm注解轉表name生成模闆生成文檔

3. 執行 comment -> name 腳本

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    
  
Private   sub   ProcessFolder(folder)    
On Error Resume Next   
      Dim   Tab   'running     table    
      for   each   Tab   in   folder.tables    
            if   not   tab.isShortcut   then    
                  tab.name   =   tab.comment   
                  Dim   col   '   running   column    
                  for   each   col   in   tab.columns    
                  if col.comment="" then   
                  else  
                        col.name=   col.comment    
                  end if  
                  next    
            end   if    
      next    
  
      Dim   view   'running   view    
      for   each   view   in   folder.Views    
            if   not   view.isShortcut   then    
                  view.name   =   view.comment    
            end   if    
      next    
  
      '   go   into   the   sub-packages    
      Dim   f   '   running   folder    
      For   Each   f   In   folder.Packages    
            if   not   f.IsShortcut   then    
                  ProcessFolder   f    
            end   if    
      Next    
end   sub
           

雙加pdm下的任意表,可以看到comment和name資料一緻

生成模闆

1.    新增模闆 : Pd中 -> 工具欄->report-> report templates... -> 打開或者建立,修改模闆

sql腳本PowerDesigner生成資料庫文檔準備sql腳本(純潔的腳本)sql腳本逆向生成pdm注解轉表name生成模闆生成文檔

2. 輕按兩下可以編輯  %***% 表達式    

3. 右鍵List  layout 可以建構表格顯示的列

生成文檔

1. 找到pdm 

2. pd->工具欄->report->Generate Reort->選擇剛剛建立的模闆-> Rtf  -> Simple chineses

sql腳本PowerDesigner生成資料庫文檔準備sql腳本(純潔的腳本)sql腳本逆向生成pdm注解轉表name生成模闆生成文檔