当前位置: 移动技术网 > IT编程>数据库>Mysql > PowerDesigner通过SQL语句生成PDM文件并将name和comment进行互相转换

PowerDesigner通过SQL语句生成PDM文件并将name和comment进行互相转换

2019年05月18日  | 移动技术网IT编程  | 我要评论

本篇文章主要介绍了powerdesigner通过sql语句生成pdm文件并将name和comment进行互相转换 超详细过程(图文),具有一定的参考价值,感兴趣的小伙伴们可以参考一下

1.软件准备

软件:navicat 11.1,powerdesigner 15

2.安装步骤

第一步:将要生成的数据库导出为sql文件

 

第二步:打开powerdesigner选择file-->reverse engineer --> database...

第三步:选择mysql5.0数据库

第四步:找到第一步生成的sql文件,点击确定即可

powerdesigner中name和comment的互相转换,需要执行语句

由于pdm 的表中 name 会默认=code 所以很不方便, 所以需要将 stereotype 显示到表的外面来

打开[工具]->[显示属性](英文:display preferences) ->content->table->右边面板columns框中 勾选: stereotype ,这样再在 stereotype中填入code字段相同内容就会显示在图形界面上了

 

使用说明: 在【tools】-【execute commands】-【edit/run script】 下。输入下面你要选择的语句即可,也可以保存起来,以便下次使用,后缀为.vbs。

 需要注意的问题是:运行语句时必须在module模式下,如果是导出报表时执行会出现错误提示。

1.name转到comment注释字段。一般情况下只填写name,comment可以运行语句自动生成。

将该语句保存为name2comment.vbs

'把pd中那么name想自动添加到comment里面
'如果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 

'   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
                     if  trim(tab.comment)="" then'如果有表的注释,则不改变它.如果没有表注释.则把name添加到注释里面.
                        tab.comment   =   tab.name
                     end if  
                  dim   col   '   running   column    
                  for   each   col   in   tab.columns   
                        if trim(col.comment)="" then '如果col的comment为空,则填入name,如果已有注释,则不添加;这样可以避免已有注释丢失.
                           col.comment=   col.name   
                        end if 
                  next    
            end   if    
      next    
  
      dim   view   'running   view    
      for   each   view   in   folder.views    
            if   not   view.isshortcut and trim(view.comment)=""  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

2.将comment内容保存到name中,comment2name.vbs 实习互换。语句为:

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

 

 

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网