博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PowerDesigner 15进行逆向工程生成数据库图表时,注释的comment的生成,解决PowerDesigner逆向工程没有列注释...
阅读量:5832 次
发布时间:2019-06-18

本文共 4434 字,大约阅读时间需要 14 分钟。

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

 

 注释列导出步骤

1、新建脚本DBMS,选择菜单:Tools→Resources→DBMS

弹出List Of DBMS对话框,选择新建

弹出新建对话框,填写名称为“My Microsoft SQL Server 2008”(这个名称可以自己定义),选择“Microsoft SQL Server 2008”,点击OK

 

上图默认文件,不需要修改,直接点保存,弹出下图

 点击展开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}select    u.name,    o.name,    c.column_id,    c.name,    case when c.system_type_id in (165, 167, 231) and c.max_length = -1 then t.name + '(Max)' else t.name end,    c.precision,    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,    c.scale,    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,    case(c.is_nullable) when 1 then 'NULL' else 'NOTNULL' end,    case(c.is_identity) when 1 then 'identity' else '' end,    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,    convert(varchar(8000), d.definition),    case (c.is_identity) when 1 then convert(varchar, i.seed_value) + ', ' + convert(varchar, i.increment_value) else '' end as colnD,    convert(varchar(8000), e.value) as colnE,    convert(varchar(8000), e.value) as colnF,    c.collation_name,    case (i.is_not_for_replication) when 1 then 'true' else 'false' end,    d.name,    case(c.is_sparse) when 1 then 'true' else 'false' end,    case(c.is_filestream) when 1 then 'true' else 'false' end,    case(c.is_rowguidcol) when 1 then 'true' else 'false' endfrom    [%CATALOG%.]sys.columns      c    join [%CATALOG%.]sys.objects o on (o.object_id = c.object_id)    join [%CATALOG%.]sys.schemas u on (u.schema_id = o.schema_id)    join [%CATALOG%.]sys.types   t on (t.user_type_id = c.system_type_id)    left outer join [%CATALOG%.]sys.identity_columns i on (i.object_id = c.object_id and i.column_id = c.column_id)    left outer join [%CATALOG%.]sys.default_constraints d on (d.object_id = c.default_object_id)    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')where    o.type in ('U', 'S', 'V')[  and u.name = %.q:OWNER%][  and o.name=%.q:TABLE%]order by 1, 2, 3
View Code

选择File→Reverse Engineer→Database 对数据库进行逆向工程,DBMS选择刚才新建的“My Microsoft SQL Server 2008”,点击确定

选择使用刚才新建的“My Microsoft SQL Server 2008”

选项按照下图选中的,点击确定

到此修改配置完成,下面开始生产逆向工程

按照下图步骤操作

 

 

点击确定

选择数据库点击OK

 

点击OK就可以生产注释的逆向工程

上面步骤数据库表的注释comment没有导出来,下面导出数据库表注释comment

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

将下面的脚本复制到上图的输入框中,点击run,就可生成表的comment注释了

'把pd中那么name想自动添加到comment里面'如果comment为空,则填入name;如果不为空,则保留不变,这样可以避免已有的注释丢失. Option Explicit ValidationMode = TrueInteractiveMode = 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
View Code

点击run,导出的表注释效果如下

 

 

PowerDesigner 15的下载链接:  提取码: r54q 

 

转载于:https://www.cnblogs.com/linJie1930906722/p/PowerDesigner.html

你可能感兴趣的文章
【cocos2d-js官方文档】十二、对象缓冲池
查看>>
php分页
查看>>
Python version 2.7 required, which was not found in the registry
查看>>
Android API level 与version对应关系
查看>>
[实战演练]Intel面试题目 - 进栈出栈顺序问题
查看>>
GATT scan的流程
查看>>
rabbitmq的发布确认和事务
查看>>
Git从码云或者Github 克隆代码到本地
查看>>
Android实例-使用电话拨号器在移动设备上(官方)(XE8+小米2)
查看>>
创建文件/目录
查看>>
结对编程总结
查看>>
我的程序员之路(九)------参加郑州微软MVP宣讲会后的一些思考
查看>>
Android学习笔记 --- 数据存储与访问 (File,sdcard,sharedpreferences,sqlite)
查看>>
UWP应用程序使用Prism框架构建MVVM
查看>>
mmap复制文件
查看>>
一个简单的根据行数对大文件进行分片的python程序
查看>>
12.16 repeater
查看>>
SoapUI 使用变量
查看>>
POJ3629 2436(CUHK summer training on 28 JUN 2012)(队列、二进制)
查看>>
大三学长带我学习JAVA.作业8。 判断101-200之间有多少个素数,并输出所有素数。...
查看>>