【转】PowerDesigner使用方法小结

简介:

PowerDesigner多用来进行数据库模型设计,具有SQL语句自动生成等功能。当然,也有不少缺点,比如团队分享。

一、设置PowerDesigner模型视图中数据表显示列

1、Tools-Display Preference…

2、窗口左边Category中General Settings下选择Table

3、窗口右边Advanced…

4、窗口左边选择Columns

5、窗口右边List columns中,选择要显示的列

 

二、设置PowerDesigner设计表时,自动将name列值中的一部分复制到code列

1、把name/code自动复制功能打开。默认是打开的。

Tool-Genneral-Options Dialog-Name to Code mirroring

2、Tools->Model Options....->Naming Convention 
3、选中Name,并勾选Enable name/code conversions. 
4、选择Name To Code

粘贴脚本代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
脚本1:
.set_value(_First, true, new)
.foreach_part(%Name%, "'#'" )
.if (%_First%)
.delete(%CurrentPart%)
.enddelete
.set_value(_First, false, update)
.else
%CurrentPart%
.endif
.next
这个例子是把Name内容的#号后边的内容当作Code.
  
脚本2:
.set_value(_First, true, new)
.foreach_part(%Name%, "'#'" )
.if (%_First%)
%CurrentPart%
.set_value(_First, false, update)
.endif
.next
  这个例子是把Name内容的#号前边的内容当作Code.

 

三、从数据库导入数据到PowerDesigner中后,将comment列值复制到name列

运行脚本 Tools->Execute Commands->Edit/Run Scripts(Ctrl Shift X)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
'******************************************************************************
'* File:     comment2name.vbs
'* Purpose:  在PowerDesigner的PDM图形窗口中显示数据列的中文注释
'* Title:    将字段的comment赋值到字段的name中
'* Category: 打开物理模型,运行本脚本(Ctrl+Shift+X)
'* Copyright:foxzz@163.com,2006/07/25 .
'* Author:   foxzz
'* Created: 
'* Modified:
'* Version:  1.0
'* Comment:  遍历物理模型中的所有表,将字段的comment赋值到字段的name中。
'            在将name置换为comment过程中,需要考虑的问题
'            1、name必须唯一,而comment有可能不唯一。
'               处理办法是如果字段的comment重复,则字段的name=comment+1、2、3...
'            2、comment值有可能为空,这种情况下对字段的name不处理。
'               针对oracle数据库,将comment on column 字段名称 is '';添加到C:/pdcomment.txt文件中。
'               在补充comment完毕后,便于在数据库中执行       
'******************************************************************************
 
Option  Explicit
ValidationMode = True
InteractiveMode = im_Batch
 
Dim  system, file
Set  system = CreateObject( "Scripting.FileSystemObject" )
Dim  ForReading, ForWriting, ForAppending   '打开文件选项
ForReading   = 1 ' 只读
ForWriting   = 2 ' 可写
ForAppending = 8 ' 可写并追加
'打开文本文件
Set  file = system.OpenTextFile( "C:/pdcomment.txt" , ForWriting, true)
 
 
'判断当前model是否物理数据模型
Dim  mdl
Set  mdl = ActiveModel
If  (mdl Is  Nothing ) Then
    MsgBox "处理对象无模型"
ElseIf  Not  mdl.IsKindOf(PdPDM.cls_Model) Then
    MsgBox "当前模型不是物理数据模型"
Else
    ProcessFolder mdl,file
End  If
file.Close
 
 
'******************************************************************************
Private  sub ProcessFolder(folder,file)
 
Dim  i,j,k
i=0:j=0:k=0
 
'列数组,记录字段里不重复的comment
Dim  ColumnComment()
Dim  ColumnCommentNumber()
ReDim  Preserve  ColumnComment(i)
ReDim  Preserve  ColumnCommentNumber(i)
 
Dim  tbl   '当前表
Dim  col   '当前字段
dim curComment  '当前字段comment
 
'处理模型中的表
for each tbl in folder.tables
     if not tbl.isShortcut then
        if len(trim(tbl.comment))<>0 then
           '可以在这里显示table的comment
           'tbl.name = tbl.name+"("+trim(tbl.comment)+")"
        end if 
 
        '处理表中的列
        for each col in tbl.columns
            k = 0
            curComment = trim(col.comment)
            if len(curComment)<>0 then
               '遍历相异的comment数组
               for j = 0 to i
                   if ColumnComment(j) = curComment then
                      '如果找到相同的comment,则相关计数器加1
                      ColumnCommentNumber(j) = ColumnCommentNumber(j) + 1
                      k = j
                   end if
               Next
               '如果没有相同的comment,则k=0,此时ColumnCommentNumber(0)也为0
               '否则ColumnCommentNumber(k)不为0
               if ColumnCommentNumber(k) <> 0 then
                  col.name = curComment & cstr(ColumnCommentNumber(k))
               else
                  col.name  = curComment
                  'ColumnComment(0)、ColumnCommentNumber(0)永远为空
                  '将相异的comment记录添加到数组中
                  i = i + 1
                  ReDim  Preserve  ColumnComment(i)
                  ReDim  Preserve  ColumnCommentNumber(i)
                  ColumnComment(i) = curComment
                  ColumnCommentNumber(i) = 0
               end if
            else
               '写入文件中
               file.WriteLine "comment on column " + tbl.name+ "." +col.code+ " is '';"          
            end if
        next
     end if
     '由于不同表的name允许相同,因此此时重新初始化。
     '因为ColumnComment(0)、ColumnCommentNumber(0)为空,可以保留
     ReDim  Preserve  ColumnComment(0)
     ReDim  Preserve  ColumnCommentNumber(0)
     i=0:j=0:k=0
 
next
 
Dim  view  '当前视图
for each view in folder.Views
     if not view.isShortcut then
        '可以在这里显示view的comment
        'view.name =  view.comment
     end if
next
 
'对子目录进行递归
Dim  subpackage 'folder
For  Each  subpackage In  folder.Packages
     if not subpackage.IsShortcut then
        ProcessFolder subpackage , file
     end if
Next
 
end sub

 

四、将name列值复制到comment列

运行脚本 Tools->Execute Commands->Edit/Run Scripts(Ctrl Shift X)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
'把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

 

参考:

1、PowerDesigner中Table视图同时显示Code和Namehttp://blog.csdn.net/downmoon/article/details/8108968

2、PowerDesigner Name/Code自动调整(转)http://hi.baidu.com/jonik/item/7d39588c3dda708e4514cf76

3、在PowerDesigner的PDM图形窗口中显示数据列的中文注释http://blog.csdn.net/zengzhe/article/details/974205

4、powerDesigner 把name项添加到注释(comment),完美方案!http://www.cnblogs.com/dukey/archive/2010/01/20/dukey.html






本文转自秋楓博客园博客,原文链接:http://www.cnblogs.com/rwxwsblog/p/5031940.html,如需转载请自行联系原作者
目录
相关文章
|
SQL 数据库 数据库管理
PowerDesigner16:导入SQL脚本、显示中文注释
PowerDesigner16:导入SQL脚本、显示中文注释
PowerDesigner16:导入SQL脚本、显示中文注释
|
Java
java: 错误: 无效的源发行版:15
java: 错误: 无效的源发行版:15
828 0
java: 错误: 无效的源发行版:15
|
Java 数据库 Spring
spring cloud 配置阿里数据库连接池 druid
spring cloud 配置阿里数据库连接池 druid
830 0
spring cloud 配置阿里数据库连接池 druid
|
算法 测试技术
详细设计文档格式
1、背景 (背景、原因) 2、名词解释 (对文档中出现新的或不常见的名词、概念或简略语给出定义和解释) 3、设计目标 3.1、实现的功能 (概要描述要实现的功能,列出要实现的功能点及子功能点,并对每一个功能点进行详细说明。
5744 0
|
数据库
PowerDesigner添加表注释
之前同事用PowerDesigner 建立数据模型后,生成到数据库中,没有注释。这导致数据库使用起来不是很方便,特别是对数据表结构不熟悉的同事。 其实,可以添加注释(并且可以逆向,即从数据库中反向更新到PDM中),方法也很简单: 在任意表上右键-属性-Columns,面板工具栏中选择Cutomize Columns and Filter(快捷键Ctrl+U),弹出对话框,勾选Comment即可。
1837 0
|
10月前
|
存储 人工智能 运维
最新榜单 | 盘点2024年10大主流工单系统
随着互联网的发展,工单系统因其多样化功能和高效管理能力,成为企业运营的重要工具。本文介绍了10大主流工单系统,包括合力亿捷、阿里云服务中台、华为云ROMA ServiceCore等,它们各具特色,帮助企业提升服务质量和运营效率,实现数字化转型。
415 7
|
存储 安全 C++
【C++ 包装器类 std::optional】全面入门指南:深入理解并掌握C++ std::optional的实用技巧与应用
【C++ 包装器类 std::optional】全面入门指南:深入理解并掌握C++ std::optional的实用技巧与应用
606 0
|
缓存 边缘计算 UED
阿里云CDN加速和全站加速DCDN区别及如何选择?
阿里云有两种加速方式,CDN加速和全站加速DCDN。前者也叫静态加速,后者叫动态加速。我们建站要速度快除了带宽大之外,比较重要的就是使用 cdn了。本文详细讲解CDN加速和全站加速DCDN的区别及如何选择。
8950 0
阿里云CDN加速和全站加速DCDN区别及如何选择?
|
机器学习/深度学习 存储 数据采集
DCFEE: A Document-level Chinese Financial Event Extraction System based on Automatically Labeled论文解读
我们提出了一个事件抽取框架,目的是从文档级财经新闻中抽取事件和事件提及。到目前为止,基于监督学习范式的方法在公共数据集中获得了最高的性能(如ACE 2005、KBP 2015)。这些方法严重依赖于人工标注的训练数据。
304 0