1. 程式人生 > 實用技巧 >PowerDesigner根據sql檔案生成表模型

PowerDesigner根據sql檔案生成表模型

經常要在PD中建表, 但是一個一個複製又比較無聊, 使用sql檔案逆向生成

  1. 拼接建表語句, 利用程式+excel,+Editplus 很容易拼接出來(commen要加: 對應pd.table中name屬性)

  2. 建表, 用PLSQL匯出sql檔案, tools–export user objects–選中表剛建的表–export

  3. 記事本開啟匯出的.sql檔案
    a. 將sql檔案中表前面 表空間+"." 全部替換為空串
    b. 另存為(解決中文亂碼)

  4. pdm建模型

在這裡插入圖片描述
在這裡插入圖片描述
在這裡插入圖片描述
在這裡插入圖片描述
此時name(左邊)是英文
在這裡插入圖片描述

在這裡插入圖片描述

執行下面指令碼, 將name改為comment內容, 點選Run

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 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
On Error Resume Next

Dim col 'running column
for each col in tab.columns
if len(col.comment) <>0 then
col.name =col.comment
end if
On Error Resume Next
next
end if
next
end sub

改table背景顏色
在這裡插入圖片描述
在這裡插入圖片描述

在這裡插入圖片描述