導出要建模的表結構腳本.sqlsql
File -> Reverse Engineer -> Database數據庫
General-DBMS:MySQL5.0(根據本身MySQL版本選擇)函數
腳本執行路徑post
備註到名稱和名稱到備註腳本 在使用PowerDesigner對數據庫進行概念模型和物理模型設計時,通常在NAME或Comment中寫中文,在Code中寫英文。Name用來顯 示,Code在代碼中使用,但Comment中的文字會保存到數據庫Table或Column的Comment中,當Name已經存在的時候,再寫一次 Comment很麻煩,能夠使用如下代碼來解決這個問題spa
'代碼一:將Name中的字符COPY至Comment中 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 comment 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 tab.comment = tab.name Dim col ' running column for each col in tab.columns col.comment= col.name next end if next Dim view 'running view for each view in folder.Views if not view.isShortcut then view.comment = view.name 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
另外在使用REVERSE ENGINEER從數據庫反向生成PDM的時候,PDM中的表的NAME和CODE事實上都是CODE,爲了把NAME替換爲數據庫中Table或Column的中文Comment,能夠使用如下腳本:設計
'代碼二:將Comment中的字符COPY至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
powerdesign小寫轉大寫(ctrl+shift+x)腳本code
'文件:powerdesigner.ucase.VBs '版本:1.0 '功能:遍歷物理模型中的全部表,將表名、表代碼、字段名、字段代碼所有由小寫改爲大寫; ' 並將序列的名和代碼由小寫改爲大寫。 '用法:打開物理模型,運行本腳本(Ctrl+Shift+X) '備註: '***************************************************************************** dim model 'current model set model = ActiveModel If (model Is Nothing) Then MsgBox "There is no current Model" ElseIf Not model.IsKindOf(PdPDM.cls_Model) Then MsgBox "The current model is not an Physical Data model." Else ProcessTables model ProcessSequences model End If '***************************************************************************** '函數:ProcessSequences '功能:遞歸遍歷全部的序列 '***************************************************************************** sub ProcessSequences(folder) '處理模型中的序列:小寫改大寫 dim sequence for each sequence in folder.sequences sequence.name = UCase(sequence.name) sequence.code = UCase(sequence.code) next end sub '***************************************************************************** '函數:ProcessTables '功能:遞歸遍歷全部的表 '***************************************************************************** sub ProcessTables(folder) '處理模型中的表 dim table for each table in folder.tables if not table.IsShortCut then ProcessTable table end if next '對子目錄進行遞歸 dim subFolder for each subFolder in folder.Packages ProcessTables subFolder next end sub '***************************************************************************** '函數:ProcessTable '功能:遍歷指定table的全部字段,將字段名由小寫改爲大寫, ' 字段代碼由小寫改爲大寫 ' 表名由小寫改爲大寫 '***************************************************************************** sub ProcessTable(table) dim col for each col in table.Columns '將字段名由小寫改爲大寫 col.code = UCase(col.code) col.name = UCase(col.name) next table.name = UCase(table.name) table.code = UCase(table.code) end sub