PowerDesigner根据sql文件生成表模型

时间:2024-04-12 18:23:46

经常要在PD中建表, 但是一个一个复制又比较无聊, 使用sql文件逆向生成

  1. 拼接建表语句, 利用程序+excel,+Editplus 很容易拼接出来(commen要加: 对应pd.table中name属性)

  2. 建表, 用PLSQL导出sql文件, tools–export user objects–选中表刚建的表–export

  3. 记事本打开导出的.sql文件
    a. 将sql文件中表前面 表空间+"." 全部替换为空串
    b. 另存为(解决中文乱码)

  4. pdm建模型

PowerDesigner根据sql文件生成表模型
PowerDesigner根据sql文件生成表模型
PowerDesigner根据sql文件生成表模型
PowerDesigner根据sql文件生成表模型
此时name(左边)是英文
PowerDesigner根据sql文件生成表模型

PowerDesigner根据sql文件生成表模型

执行下面脚本, 将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背景颜色
PowerDesigner根据sql文件生成表模型
PowerDesigner根据sql文件生成表模型

在这里插入图片描述