PowerDesigner逆向工程导入表结构

PowerDesigner逆向生成表结构

PowerDesginer逆向工程提供两种导入表结构的方式:

  1. Using script files:使用脚本文件,即通过其他软件到处数据库表结构的.sql文件
  2. Using a data source:使用一个数据库源,直接连接数据库进行导入

Using script files

  • 从Navicat导出.sql文件,该文件保存了数据库表结构。

    这里不再阐述Navicat导出.sql文件的具体操作。

    以下为导出的实例sql语句:

    SET FOREIGN_KEY_CHECKS=0;
    
    DROP TABLE IF EXISTS `account`;
    CREATE TABLE `account` (
    `accountid`  varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '账户标识' ,
    `userid`  varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '用户标识' ,
    `accountrole`  varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '账户角色' ,
    `balance`  decimal(20,2) NULL DEFAULT 0.00 COMMENT '账户余额' ,
    `availablebalance`  decimal(20,2) NULL DEFAULT 0.00 COMMENT '可用余额' ,
    `platform`  varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '平台标识' ,
    `tenantid`  varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL ,
    `lastupdateduserid`  varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL ,
    `lastupdatedstamp`  datetime NULL DEFAULT NULL ,
    `createduserid`  varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL ,
    `createdstamp`  datetime NULL DEFAULT NULL ,
    `deleted`  varchar(1) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL ,
    PRIMARY KEY (`accountid`)
    )
    ENGINE=InnoDB
    DEFAULT CHARACTER SET=utf8 COLLATE=utf8_general_ci;
    

    注意:我们需要对该表进行适当修改,才能使得PowerDesigner正确的读入注释信息,否则大部分的注释将丢失。

    修改一:去掉各个字段和表的字符集设置和查询校验规则

    SET utf8 COLLATE utf8_general_ci
    

    修改二:去掉表引擎设置

    ENGINE=InnoDB
    
  • 将sql文件导入到PowerDesigner

    这里我采用了两种导入方式:

    方式一

    点击File>>Reverse Engineer>>Database…

逆向生成表_01.png

逆向生成表_02.png

方式二

点击DataBase>>Update Model from Database

逆向生成表_02.png

现在导入的表已经包含了注释信息,但是我们从表图形上依然看不到注释信息。

表内部数据:

逆向生成表_03.png

表显示界面:

逆向生成表_04.png

  • 将注释信息显示在表上

点击Tools>>Execute Commands>>Edit/Run Script

显示如下图:

逆向生成表_05.png

输入以下两种脚本执行实现数据替换:

将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 
                  tab.comment   =   tab.name 
                  Dim   col   '   running   column 
                  for   each   col   in   tab.columns 
                        col.comment=   col.name 
                  next 
            end   if 
      next
 
      Dim   view   'running   view 
      for   each   view   in   folder.Views 
            if   not   view.isShortcut   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

将Name数据替换为Comment数据:(我们需要达到的效果)

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

利用第二种脚本实现效果如下:

逆向生成表_06.png

逆向生成表_07.png


Using a data source

数据库连接注意:

  • PowerDesigener连接数据库需要对应数据库驱动的支持,如果安装驱动后依然没有识别出对应驱动,则换一下驱动位数(32/64位)即可。

  • 创建Physical Data Model

逆向生成表_08.png

  • 导入表结构

点击:File>>Reverse Engineer>>Database…

逆向生成表_01.png

注意选对DBMS:第二行DNMS选项选择对应的数据库版本,如果导入后的表只显示表名二丢失字段、注释、数据类型等信息,往往是DBMS没有设置正确。

逆向生成表_09.png

逆向生成表_10.png
可以看到目前还没有连接任何数据库,因此点击Configure创建数据库连接

逆向生成表_11.png

逆向生成表_12.png

选择对应的数据库连接驱动

注意:如果没有对应的数据库驱动程序则需要自行安装,同时需要注意驱动程序的版本和位数(32/64)。如果安装位数不正确,PowerDesigener是识别不了的。

逆向生成表_13.png

逆向生成表_14.png

逆向生成表_15.png

输入连接信息,测试是否连接成功

逆向生成表_16.png

逆向生成表_17.png

逆向生成表_18.png

逆向生成表_19.png

除了在PowerDesigener内部连接数据库,也可以不启动PowerDesigener连接:

首先打开:控制面板>所有控制面板选项>管理工具

逆向生成表_20.png

逆向生成表_21.png

图中分别用于设置32位和64位的数据源,其连接操作同上文操作一致

网络资源链接

https://blog.csdn.net/chao_1990/article/details/52620206

https://www.cnblogs.com/leilong/p/8926318.html

https://blog.csdn.net/Demis_demis/article/details/83038715

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值