上一章讲了对数据库进行逆向工程生成图表操作,可能会遇到无法生成注释的问题:

一、解决PowerDesigner逆向工程没有列注释

1、打开PowerDesigner 15,选择菜单:File→Reverse Engineer→Database 对数据库进行逆向工程生成PDM图表,选择一张表生成:

              

生成后双击图表,打开表属性,选择Columns选项,可以看到注释却是空的,而数据库里的表是有注释的

          

2、选择菜单:Database→Edit Current DBMS,弹出DBMS Properties对话框,选择Script\Objects\Column\SqlListQuery

3、可以看到其Value为:

  1. {OWNER, TABLE, S, COLUMN, DTTPCODE, LENGTH, SIZE, PREC, COMPUTE, NOTNULL, IDENTITY, DOMAIN, DEFAULT, ExtIdentitySeedInc, COMMENT, ExtCollation, ExtIdtNotForReplication, ExtDeftConstName, Sparse, FileStream, ExtRowGuidCol}
  2.  
  3. select
  4. u.name,
  5. o.name,
  6. c.column_id,
  7. c.name,
  8. case when c.system_type_id in (165, 167, 231) and c.max_length = -1 then t.name + '(Max)' else t.name end,
  9. c.precision,
  10. case (c.max_length) when -1 then 0 else case when c.system_type_id in (99, 231, 239) then (c.max_length/2) else (c.max_length) end end as colnA,
  11. c.scale,
  12. case(c.is_computed) when 1 then convert(varchar(8000), (select z.definition from [%CATALOG%.]sys.computed_columns z where z.object_id = c.object_id and z.column_id = c.column_id)) else '' end as colnB,
  13. case(c.is_nullable) when 1 then 'NULL' else 'NOTNULL' end,
  14. case(c.is_identity) when 1 then 'identity' else '' end,
  15. case when(c.user_type_id <> c.system_type_id) then (select d.name from [%CATALOG%.]sys.types d where d.user_type_id = c.user_type_id) else '' end as colnC,
  16. convert(varchar(8000), d.definition),
  17. case (c.is_identity) when 1 then convert(varchar, i.seed_value) + ', ' + convert(varchar, i.increment_value) else '' end as colnD,
  18. (select convert(varchar(8000), value) from ::fn_listextendedproperty(NULL, 'user', u.name, 'table', o.name, 'column', c.name) where name = 'MS_Description') as colnE,
  19. c.collation_name,
  20. case (i.is_not_for_replication) when 1 then 'true' else 'false' end,
  21. d.name,
  22. case(c.is_sparse) when 1 then 'true' else 'false' end,
  23. case(c.is_filestream) when 1 then 'true' else 'false' end,
  24. case(c.is_rowguidcol) when 1 then 'true' else 'false' end
  25. from
  26. [%CATALOG%.]sys.columns c
  27. join [%CATALOG%.]sys.objects o on (o.object_id = c.object_id)
  28. join [%CATALOG%.]sys.schemas u on (u.schema_id = o.schema_id)
  29. join [%CATALOG%.]sys.types t on (t.user_type_id = c.system_type_id)
  30. left outer join [%CATALOG%.]sys.identity_columns i on (i.object_id = c.object_id and i.column_id = c.column_id)
  31. left outer join [%CATALOG%.]sys.default_constraints d on (d.object_id = c.default_object_id)
  32. where
  33. o.type in ('U', 'S', 'V')
  34. [ and u.name = %.q:OWNER%]
  35. [ and o.name=%.q:TABLE%]
  36. order by 1, 2, 3

原脚本

将其修改一下就可以了。

  1. {OWNER, TABLE, S, COLUMN, DTTPCODE, LENGTH, SIZE, PREC, COMPUTE, NOTNULL, IDENTITY, DOMAIN, DEFAULT, ExtIdentitySeedInc,COMMENT, ExtCollation, ExtIdtNotForReplication, ExtDeftConstName, Sparse, FileStream, ExtRowGuidCol}
  2.  
  3. select
  4. u.name,
  5. o.name,
  6. c.column_id,
  7. c.name,
  8. case when c.system_type_id in (165, 167, 231) and c.max_length = -1 then t.name + '(Max)' else t.name end,
  9. c.precision,
  10. case (c.max_length) when -1 then 0 else case when c.system_type_id in (99, 231, 239) then (c.max_length/2) else (c.max_length) end end as colnA,
  11. c.scale,
  12. case(c.is_computed) when 1 then convert(varchar(8000), (select z.definition from [%CATALOG%.]sys.computed_columns z where z.object_id = c.object_id and z.column_id = c.column_id)) else '' end as colnB,
  13. case(c.is_nullable) when 1 then 'NULL' else 'NOTNULL' end,
  14. case(c.is_identity) when 1 then 'identity' else '' end,
  15. case when(c.user_type_id <> c.system_type_id) then (select d.name from [%CATALOG%.]sys.types d where d.user_type_id = c.user_type_id) else '' end as colnC,
  16. convert(varchar(8000), d.definition),
  17. case (c.is_identity) when 1 then convert(varchar, i.seed_value) + ', ' + convert(varchar, i.increment_value) else '' end as colnD,
  18. convert(varchar(8000), e.value) as colnE,
  19. c.collation_name,
  20. case (i.is_not_for_replication) when 1 then 'true' else 'false' end,
  21. d.name,
  22. case(c.is_sparse) when 1 then 'true' else 'false' end,
  23. case(c.is_filestream) when 1 then 'true' else 'false' end,
  24. case(c.is_rowguidcol) when 1 then 'true' else 'false' end
  25. from
  26. [%CATALOG%.]sys.columns c
  27. join [%CATALOG%.]sys.objects o on (o.object_id = c.object_id)
  28. join [%CATALOG%.]sys.schemas u on (u.schema_id = o.schema_id)
  29. join [%CATALOG%.]sys.types t on (t.user_type_id = c.system_type_id)
  30. left outer join [%CATALOG%.]sys.identity_columns i on (i.object_id = c.object_id and i.column_id = c.column_id)
  31. left outer join [%CATALOG%.]sys.default_constraints d on (d.object_id = c.default_object_id)
  32. left outer join [%CATALOG%.]sys.extended_properties e on (e.class=u.schema_id and e.major_id=o.object_id and e.minor_id = c.column_id and e.name=N'MS_Description')
  33. where
  34. o.type in ('U', 'S', 'V')
  35. [ and u.name = %.q:OWNER%]
  36. [ and o.name=%.q:TABLE%]
  37. order by 1, 2, 3

新脚本

4、这里我为了以后还可以使用原先的脚本DBMS(也就是自带的Microsoft SQL Server 2008),我新建一个自定义的“My Microsoft SQL Server 2008”:选择菜单,Tools→Resources→DBMS,弹出List Of DBMS对话框,选择新建,弹出新建对话框,填写名称为“My Microsoft SQL Server 2008”,选择“Microsoft SQL Server 2008”从此复制,Ok,保存。

             

5、保存后,弹出DBMS Properties对话框,选择Script\Objects\Column\SqlListQuery,修改其Value就可以了,Value的值就是上面的“新脚本”的值。

6、选择File→Reverse Engineer→Database 对数据库进行逆向工程,DBMS选择刚才新建的“My Microsoft SQL Server 2008”,这样生成的表就有注释了。

                  

二、让列的Name自动设为为Comment的中文意思:

1、在刚才新建的“My Microsoft SQL Server 2008”的Script\Objects\Column中可以看到这么一段:

  1. The following system variables are available:
  2. (parent table items are also available for columns)
  3. "COLUMN" // generated code of the column
  4. "COLNNO" // position of the column in the list of columns of the table
  5. "COLNNAME" // name of the column
  6. "COLNCODE" // code of the column
  7. "PRIMARY" // keyword "primary" if the column is primary
  8. "ISPKEY" // TRUE if the column is part of the primary key
  9. "FOREIGN" // TRUE if the column is part of one foreign key

2、将COLNNAME添加到Script\Objects\Column\SqlListQuery的Value中,{OWNER, TABLE, S, COLUMN, DTTPCODE, LENGTH, SIZE, PREC, COMPUTE, NOTNULL, IDENTITY, DOMAIN, DEFAULT, ExtIdentitySeedInc,COMMENT,COLNNAME, ExtCollation, ExtIdtNotForReplication, ExtDeftConstName, Sparse, FileStream, ExtRowGuidCol},再把Comment的值给它

现在生成效果就很好了:

3、也可以不用这种方式来完成Name自动设为Comment,可以利用vbs脚本完成

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

Comment2Name

选择菜单:Tools→Execute Commands→Edit/Run Script,Run运行vbs脚本即可。

 

4、将Name的值设给Comment

  1. '把pd中那么name想自动添加到comment里面
  2. '如果comment为空,则填入name;如果不为空,则保留不变,这样可以避免已有的注释丢失.
  3.  
  4. Option Explicit
  5. ValidationMode = True
  6. InteractiveMode = im_Batch
  7.  
  8. Dim mdl ' the current model
  9.  
  10. ' get the current active model
  11. Set mdl = ActiveModel
  12. If (mdl Is Nothing) Then
  13. MsgBox "There is no current Model "
  14. ElseIf Not mdl.IsKindOf(PdPDM.cls_Model) Then
  15. MsgBox "The current model is not an Physical Data model. "
  16. Else
  17. ProcessFolder mdl
  18. End If
  19.  
  20. ' This routine copy name into comment for each table, each column and each view
  21. ' of the current folder
  22. Private sub ProcessFolder(folder)
  23. Dim Tab 'running table
  24. for each Tab in folder.tables
  25. if not tab.isShortcut then
  26. if trim(tab.comment)="" then '如果有表的注释,则不改变它.如果没有表注释.则把name添加到注释里面.
  27. tab.comment = tab.name
  28. end if
  29. Dim col ' running column
  30. for each col in tab.columns
  31. if trim(col.comment)="" then '如果colcomment为空,则填入name,如果已有注释,则不添加;这样可以避免已有注释丢失.
  32. col.comment= col.name
  33. end if
  34. next
  35. end if
  36. next
  37.  
  38. Dim view 'running view
  39. for each view in folder.Views
  40. if not view.isShortcut and trim(view.comment)="" then
  41. view.comment = view.name
  42. end if
  43. next
  44.  
  45. ' go into the sub-packages
  46. Dim f ' running folder
  47. For Each f In folder.Packages
  48. if not f.IsShortcut then
  49. ProcessFolder f
  50. end if
  51. Next
  52. end sub

Name2Comment

使用PowerDesigner 15进行逆向工程生成数据库图表时,列的注释问题的更多相关文章

  1. PowerDesigner 15进行逆向工程生成数据库图表时,注释的comment的生成,解决PowerDesigner逆向工程没有列注释

    使用PowerDesigner默认配置逆向工程是没有注释(name列为英文,comment列是空的),这样的不方便查看字段具体是什么意义,将注释一同导出,方便查看字段具体的意义,如下图 注释列导出步骤 ...

  2. 使用SchemaSpy逆向工程生成数据库依赖关系使用SchemaSpy工具可以快速的从数据库中得到

    使用SchemaSpy逆向工程生成数据库依赖关系    使用SchemaSpy工具可以快速的从数据库中得到表的依赖关系,同时生成一个生动的“表图”结合的报告.方便快速了解数据库中的数据库对象间关系,类 ...

  3. Mybatis Generator生成数据库自带的中文注释

    1.相关jar包 <!-- mybatis生成 jar包 --> <dependency> <groupId>org.mybatis.generator</g ...

  4. powerdesigner 15.1 逆向工程 sqlserver2008 、sqlserver2005 带注释

    第一种方法:在第一个网址里面的代码可以直接赋值到对应位置即可 http://wjqe.blog.163.com/blog/static/19938452011612536439/ 第二种方法:可塑性较 ...

  5. EntityFramework Core 2.x (ef core) 在迁移中自动生成数据库表和列说明

    在项目开发中有没有用过拼音首字母做列名或者接手这样的项目? 看见xmspsqb(项目审批申请表)这种表名时是否有一种无法抑制的想肛了取名的老兄的冲动? 更坑爹的是这种数据库没有文档(或者文档老旧不堪早 ...

  6. Django 生成数据库表时的报错TypeError: __init__() missing 1 required positional argument: 'on_delete'

    原因及解决办法: https://www.cnblogs.com/phyger/p/8035253.html

  7. idea 中使用Mybatis Generator逆向工程生成代码

    通过MAVEN完成 Mybatis 逆向工程 1. POM文件中添加插件 在 pom 文件的build 标签中 添加 plugin 插件和 数据库连接 jdbc 的依赖. <build> ...

  8. 使用PowerDesign15反向生成数据库

           在Pd15中建立物理模型后,可以通过反向工程直接生成数据库的表结构.主要有以下几个步骤: 1. 首先设置一下数据库配置,选择对应要使用的数据库(此处选择Sql Server 2008 R ...

  9. FusionCharts生成Flash图表常见问题FAQ

    本文主要汇总了FusionCharts生成Flash图表时的一些常见问题(FAQ)以及解决方法/调试方法,欢迎交流! 问题描述:利用FusionCharts创建Flash图表时,能否直接从数组或rec ...

随机推荐

  1. css实现连续数字和英文的自动换行的方法

    1.(IE浏览器)连续的英文字符和阿拉伯数字,使用word-wrap : break-word ;或者word-break:break-all;实现强制断行 #wrap{word-break:brea ...

  2. Node.js_文件系统 FS

    文件系统 FS——File System 所谓的文件系统,就是对计算机中的文件进行增.删.查.改等操作 是一个服务器的基础 node 通过核心 FS 模块来操作文件系统 简单写 // 1. 导入 fs ...

  3. mac charles抓安卓(小米)http包

    网上有很多的教程说明如何操作,都写的很好,比如 https://blog.csdn.net/luochoudan/article/details/72801573,我在这里补充一点,非常重要的一点:手 ...

  4. DjangoRestFramework学习二之序列化组件、视图组件 serializer modelserializer

      DjangoRestFramework学习二之序列化组件.视图组件   本节目录 一 序列化组件 二 视图组件 三 xxx 四 xxx 五 xxx 六 xxx 七 xxx 八 xxx 一 序列化组 ...

  5. Ultimate Guide to WhatsApp for Business 2019

    By Iaroslav Kudritskiy (Source: https://rocketbots.io/blog/the-ultimate-guide-to-whatsapp-business-a ...

  6. python 科学计算与可视化

    一.Numpy 库 NumPy(Numerical Python) 是 Python 语言的一个扩展程序库,支持大量的维度数组与矩阵运算,此外也针对数组运算提供大量的数学函数库. 引用: import ...

  7. c++ 第一次实验

    实验内容: 2-28:实现一个简单的菜单程序,运行时显示“Menu:A(dd) D(elete) S(ort) Q(uit),Selete one:”提示用户输入.A表示增加,D表示删除, S表示排序 ...

  8. Ext选项卡tabpanel切换动态加载数据

    鸣人不说暗话,来张图: 代码开始:(使用Ext,ajax加载数据,如果你们有好的方法也可以多多交流)var tabxsk = new Object(); //初始化 tabxsk.init = fun ...

  9. linux netcat 命令详解

    功能说明:强大的网络工具语 法:nc [-hlnruz][-g<网关...>][-G<指向器数目>][-i<延迟秒数>][-o<输出文件>][-p< ...

  10. 2019春第十周作业Compile Summarize

    这个作业属于那个课程 C语言程序设计II 这个作业要求在哪里 在这里 我在这个课程的目标是 能够对C语言的编写更加得心应手 这个作业在那个具体方面帮助我实现目标 结构体更进一步 参考文献与网址 C语言 ...