PowerDesigner使用实践

PowerDesigner使用实践

一、前言

1.简介

PowerDesigner DataArchitect 是业界领先的数据建模工具。 它提供了一种模型驱动的方法来增强业务和 IT 的能力并使其保持一致。 PowerDesigner 使企业能够更轻松地可视化、分析和操作元数据,以实现有效的企业信息架构。

PowerDesigner 独特地结合了多种数据建模技术(传统的概念、逻辑和物理建模与独特的商业智能和数据移动建模),将业务分析与正式的数据库设计解决方案结合在一起。 PowerDesigner 可与 60 多个关系数据库管理系统配合使用。

使用独特的链接和同步技术完全集成模型。 模型集成了所有模型类型,以进行完整的企业范围或项目范围的影响分析。 影响分析简化了沟通和协作,从而显着提高整个组织对变革的响应能力。

2.环境

  • Windows 10
  • Power Designer 15.2

PowerDesigner 官网:https://www.powerdesigner.biz/

PowerDesigner 百度百科:https://baike.baidu.com/item/power%20designer

二、使用实践

1.导入MySQL表

1)MySQL客户端导出表
  • 使用 Navicat 导出数据库结构

在这里插入图片描述

2)修改SQL语句
  • 由于PD无法解析部分SQL建表语句,导致注释(Comment)丢失,所以需要去掉部分SQL语句

(1)字符

  • 原内容:
`titile` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '标题'
  • 修改为:
`titile` varchar(100)  NULL DEFAULT NULL COMMENT '标题'
  • 以下 3 个SQL语句替换为空字符串:
CHARACTER SET utf8 COLLATE utf8_general_ci

CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci

CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci

(2)时间

  • 原内容:
`create_time` datetime(0) NULL DEFAULT NULL COMMENT '创建时间',
  • 修改为:
`create_time` datetime NULL DEFAULT NULL COMMENT '创建时间',
  • datetime(0) 替换为 datetime
3)导入MySQL表
  • File - Reverse Engineer - Database…

在这里插入图片描述

  • 输入数据模型名称
  • 选择 MySQL 5.0

在这里插入图片描述

  • 选择 SQL 文件,然后点击确定

在这里插入图片描述

2.Name替换为注释(Comment)

  • Tools - 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
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

3.取消Name和Code的关联

  • Tools - General Options…

在这里插入图片描述

  • 勾选 Name to Code mirroring

在这里插入图片描述

4.表设计自定义列

  • 自定义列

在这里插入图片描述

  • 勾选 Comment

在这里插入图片描述

  • 最终效果

在这里插入图片描述

5.设置格式(样式)

  • 表模型 - 右击 - Format…

在这里插入图片描述

  • 修改背景色

在这里插入图片描述

6.创建物理模型

  • File - New Model…

在这里插入图片描述

  • Model types - Physical Diagram
  • 填写数据模型名称,选择 MySQL 5.0

在这里插入图片描述

7.表模型显示注释(Comment)

  • 表模型显示出第三列,效果如下:

在这里插入图片描述

  • Model - Extended Model Definitions…

在这里插入图片描述

  • 点击空白处

在这里插入图片描述

  • 点击 Properties 按钮

在这里插入图片描述

  • Profile - Add Metaclasses…

在这里插入图片描述

  • 勾选 Column

在这里插入图片描述

  • Column - New - Extended Attribute

在这里插入图片描述

  • General 选项卡

在这里插入图片描述

  • %Get% = “” 更改为 %Get% = Rtf2Ascii (obj.Comment)

在这里插入图片描述

在这里插入图片描述

  • Tools - Display Preferences…

在这里插入图片描述

  • Table - Advanced…

在这里插入图片描述

  • Columns - 点击 Select 按钮

在这里插入图片描述

  • 勾选刚刚新建的 Attribute Name

在这里插入图片描述

  • 表模型显示注释列

在这里插入图片描述

8.修改全部表的字段属性

  • Tools - Execute Commands - Edit/Run Script…

在这里插入图片描述

  • 运行脚本,脚本内容:

场景:修改全部表的 create_by 和 update_by 的字段长度为 100

Option Explicit
ValidationMode = True
InteractiveMode = im_Batch
 
' Created by runnerrunning 
 
' Get the current active model
Dim mdl ' The current model
Set mdl = ActiveModel
If (mdl Is Nothing) Then
   MsgBox "There is no Active Model"
Else
   ListObjects(mdl)
End If
 
'-----------------------------------------------------------------------------
Private Sub ListObjects(fldr) ' List all objects
   output "Scanning " & fldr.code
   Dim obj ' Running object
   
   For Each obj In fldr.children
      ' Calling sub procedure to print out information on the object
      TableSetComment obj
   Next
 
   	' Go into the sub-packages
   Dim f ' Running folder
   For Each f In fldr.Packages ' Recursively call to list all objects
      ' Calling sub procedure to scan children package
      ListObjects f
   Next
End Sub
 
Private Sub TableSetComment(CurrentObject)
   if not CurrentObject.Iskindof(cls_Table) then exit sub
   
   Dim col  ' Running column
   for each col in CurrentObject.columns
      ' Check for specific column names and update length if matched
      if col.Code="create_by" or col.Code="update_by" then
         output "Updating " & CurrentObject.Name & " - " & col.Code
         col.Length = 100
      end if
   next
End Sub
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

趴着喝可乐

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值