PowerDesigner导入sql脚本(同时保证注释不丢失及name copy comment)

写在前面

一个好的数据库建模,不但可以让人直观的理解模型,充分的利用数据库技术,优化数据库的设计,而且还可以让新员工快速的熟悉数据库表结构与业务之间的关系.无奈的是随着开发过程中,数据库表结构字段的增删以及关联关系的变动给数据库模型带来维护上的巨大工作量.现为了维护上的简单,介绍一种快速维护数据库模型的方式,PowerDesigner导入sql脚本的方式.

正文

  首先,是一份写好的sql脚本

  然后,上图

1.依次点击File->Reverse Engineer->Database...

2.弹出弹窗对模型进行命名,同时在DBMS下拉选择框中需要选择自己对应的数据库类型,点击确定

3.新的弹窗,选中Using script files,再点击红圈中,选中你的sql脚本位置,点击确定

4,结果图

ok,导入sql脚本成功,并且生成了模型

 

补充

1.注释丢失.由于Sql转模型的时候,会因为格式不符合PowerDesigner的标准或者数据库类型与PowerDesigner的类型对应不上等杂七杂八的原因会造成注释的丢失,这是我们需要将sql的格式改成符合PowerDesigner的规范,重新进行导入就行了.

修改前: `ct_no` varchar(30) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '反恐舱单编号;如ams编号'

修改后:`ct_no` varchar(30)  NULL DEFAULT NULL COMMENT '反恐舱单编号;如ams编号'

 

修改前:`create_time` datetime(0) NULL DEFAULT NULL COMMENT '创建时间'

修改后:`create_time` datetime NULL DEFAULT NULL COMMENT '创建时间'

 

结论:可以适当的修改表结构使得PowerDesigner更加适合导入sql,从而显示中文注释

2.如何让Name里面的值显示的是comment里面的值

在使用REVERSE ENGINEER从数据库反向生成PDM的时候,PDM中的表的NAME和CODE事实上都是CODE,为了把NAME替换为数据库中Table或Column的中文Comment,可以使用以下脚本:

在PowerDesigner中使用方法为:

PowerDesigner->Tools->Execute Commands->Edit/Run Scripts

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

结果图如下:

3.有时我们生成的物理模型所包含的表结构太多了,这是对于我们来说查看某一个表结构会显得格外困难,这里介绍一种PowerDesigner里查找特定的表.

3.1.crtl+f查找,在code处输入你要查找的表名,然后点击“find now".

3.2.右击找到的表,点击”find in diagram"即可.

 

参考链接:https://www.cnblogs.com/xiaotao726/p/6841811.html

参考链接:https://www.cnblogs.com/fjrgg/p/9682804.html

发布了33 篇原创文章 · 获赞 33 · 访问量 11万+

猜你喜欢

转载自blog.csdn.net/qq_36090463/article/details/94732758