PowerDesigner导入sql脚本

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

1、前提

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

2、具体操作

1.依次点击File->Reverse Engineer->Database…(中文破解如下图操作)
在这里插入图片描述

2.1 模型命名

弹出弹窗对模型进行命名,同时在DBMS下拉选择框中需要选择自己对应的数据库类型,点击确定
在这里插入图片描述

2.2 导入sql脚本

新的弹窗,选中Using script files,再点击红圈中,选中你的sql脚本位置,点击确定
在这里插入图片描述

2.3 成功页面

导入sql脚本成功,并且生成了模型在这里插入图片描述

3 模型注释丢失处理

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

3.1 varchar类型

把导出的CHARACTER SET utf8 COLLATE utf8_general_ci替换为空,举例如下

错误写法

 `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编号'

3.2 datetime类型

把导出的datetime(0) 替换为datetime,举例如下

错误写法

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

正确写法

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

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

4 让Name里面的值显示的是comment里面的值

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

4.1 书写转换脚本

打开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

在这里插入图片描述

在这里插入图片描述
参考链接https://www.cnblogs.com/xiaotao726/p/6841811.html

猜你喜欢

转载自blog.csdn.net/qq_37493556/article/details/106318171