PowerDesigner导入Mysql SQL文件如何自动显示comment?

文章介绍了如何在PowerDesigner中通过处理从MySQL导出的数据库脚本,使用VBA脚本来更新表和列的名称,使其与MySQL中的comment字段同步。过程包括从Navicat导出结构,删除字符设定,然后在PowerDesigner中进行反向工程和执行特定的VBA代码来更新模型中的名称。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

PowerDesigner 中name即是显示在ER图中的名称,而MySQL中所设定的为comment,因此如果想显示出名称,需要做如下步骤处理。

  1. 从数据库中导出结构

Navicat中,选中数据库,右键-》转储SQL文件-》选择 仅结构,导出数据库脚本

  1. 整理sql文件,将字符设定去除

如:CHARACTER SET utf8,COLLATE utf8_bin等

  1. 使用File->Reverse Engineer->database

使用数据库文件导入,如下图:

  1. 执行脚本生成名称

执行脚本窗口:工具-》Execute commands-》Edit/Run Script...

执行如下语句

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
'tab.name = tab.comment&"["&tab.name&"]"
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

该语句中:对表名的设定语句仍有问题,待修改

注意:如果语句中没有comment 则无法将字段名显示出来

参考:https://lddwarehouse.blog.youkuaiyun.com/article/details/128365126

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值