powerdesigner逆向工程生成PDM时的列注释解决方案
在用powerdesigner 逆向 工程 生成 PDM时,列 注释 (ColumnComment)始终无法 生成 ,历经数小时的探索,找到一个折衷的方法,现分享如下。并希望有高手指点更好的方法。 邀月使用的是Powerdesigner 15.2,数据库为SQL Server 2008 r2 方法如下: 1、在PowerD
在用powerdesigner逆向工程生成PDM时,列注释(ColumnComment)始终无法生成,历经数小时的探索,找到一个折衷的方法,现分享如下。并希望有高手指点更好的方法。
邀月使用的是Powerdesigner 15.2,数据库为SQL Server 2008 r2
方法如下:
1、在PowerDesigner界面-File-Reverse Engineer-Database,然后选择一个DBMS,我这里选取一个由系统默认的SQL Server 2008 DBMS修改而来的SQL_2008_MyDefine。
选好odbc,输入正确的连接串,选择数据库及表。
生成效果:Name为英文,且Comment列为空。
而我们希望的是Name列为中文,Comment为中文。
查看了下在线帮助,发现在SQL_2008_MyDefine::Script\Objects\Column\SqlListQuery下的Value值如下:
{OWNER, TABLE, S, COLUMN, DTTPCODE, LENGTH, SIZE, PREC, COMPUTE, NOTNULL, IDENTITY, DOMAIN, DEFAULT, ExtIdentitySeedInc, COMMENT, 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, (select convert(varchar(8000), value) from ::fn_listextendedproperty(NULL, 'user', u.name, 'table', o.name, 'column', c.name) where name = 'MS_Description') as colnE, 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' end from [%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) where o.type in ('U', 'S', 'V') [ and u.name = %.q:OWNER%] [ and o.name=%.q:TABLE%] order by 1, 2, 3
注意该值中上面是PDM对应的列名,下面是从SQL数据库中取到的相关属性值。其中“
(selectconvert(varchar(8000), value) from
::fn_listextendedproperty(NULL, 'user', u.name, 'table', o.name, 'column', c.name)
where name ='MS_Description') as colnE,
”是可以取到Comment值的,可是生成的PDM为什么Comment列为空呢?尝试修改该SQL语句,将语句提取出来,也可以获取结果:
select
u.name,
o.name,
c.column_id,
c.name,
casewhen c.system_type_id in (165, 167, 231) and c.max_length =-1then t.name +'(Max)'else t.name end,
c.precision,
case (c.max_length) when-1then0elsecasewhen c.system_type_id in (99, 231, 239) then (c.max_length/2) else (c.max_length) endendas colnA,
c.scale,
case(c.is_computed) when1thenconvert(varchar(8000), (select z.definition from sys.computed_columns z where z.object_id= c.object_idand z.column_id = c.column_id)) else''endas colnB,
case(c.is_nullable) when1then'NULL'else'NOTNULL'end,
case(c.is_identity) when1then'identity'else''end,
casewhen(c.user_type_id c.system_type_id) then (select d.name from sys.types d where d.user_type_id = c.user_type_id) else''endas colnC,
convert(varchar(8000), d.definition),
case (c.is_identity) when1thenconvert(varchar, i.seed_value) +', '+convert(varchar, i.increment_value) else''endas colnD,
(selectconvert(varchar(8000), value) from ::fn_listextendedproperty(NULL, 'user', u.name, 'table', o.name, 'column', c.name) where name ='MS_Description') as colnE,
c.collation_name,
case (i.is_not_for_replication) when1then'true'else'false'end,
d.name,
case(c.is_sparse) when1then'true'else'false'end,
case(c.is_filestream) when1then'true'else'false'end,
case(c.is_rowguidcol) when1then'true'else'false'end
from
sys.columns c
join sys.objects o on (o.object_id= c.object_id)
join sys.schemas u on (u.schema_id = o.schema_id)
join sys.types t on (t.user_type_id = c.system_type_id)
leftouterjoin sys.identity_columns i on (i.object_id= c.object_idand i.column_id = c.column_id)
leftouterjoin sys.default_constraints d on (d.object_id= c.default_object_id)
where
o.type in ('U', 'S', 'V')
and u.name =N'dbo'
and o.name=N'Age'
orderby1, 2, 3
后来发现,直接用生成表的SQL,而不是用数据库就可以生成注释。如下图:
但字段类型全乱了。
难道Powerdesigner真的这么弱吗?google了一下,看到官方文档:
http://manuals.sybase.com/onlinebooks/group-pd/pdd1100e/advanced/@Generic__BookTextView/1302;hf=0
里面有关于SqlListQuery的解释。
再看看上面的SQL语句,突然想到,既然可以在SQL查询出结果,那么出错一定在生成PDM的时候,
在SQL_2008_MyDefine::Script\Objects\Column中看到这么一段:
The following system variables are available:
(parent table items are also available for columns)
"COLNNAME" // name of the column
"COLNCODE" // code of the column
将上面的Value值中上面的一行中“Comment”修改为“COLNNAME”会如何?即
{OWNER, TABLE, S, COLUMN, DTTPCODE, LENGTH, SIZE, PREC, COMPUTE, NOTNULL, IDENTITY, DOMAIN, DEFAULT, ExtIdentitySeedInc, COMMENT, ExtCollation, ExtIdtNotForReplication, ExtDeftConstName, Sparse, FileStream, ExtRowGuidCol}改为
{OWNER, TABLE, S, COLUMN, DTTPCODE, LENGTH, SIZE, PREC, COMPUTE, NOTNULL, IDENTITY, DOMAIN, DEFAULT, ExtIdentitySeedInc, COLNNAME, ExtCollation, ExtIdtNotForReplication, ExtDeftConstName, Sparse, FileStream, ExtRowGuidCol}
结果生成如下:
同理将SQL_2008_MyDefine::Script\Objects\Table\SqlListQuery下的Value的第一行中
{OWNER, TABLE, TABLE_TYPE, Comment}的Comment改为{OWNER, TABLE, TABLE_TYPE, TNAME}
生成结果,如下:
至此,我的基本目的,已经达到了,虽然没有直接生成Comment列,但可以通过以下vbs脚本,从Name列生成Comment列:
'代码一:将name生成comment的脚本
OptionExplicit
ValidationMode =True
InteractiveMode = im_Batch
Dim mdl 'the current model
'get the current active model
Set mdl = ActiveModel
If (mdl IsNothing) Then
MsgBox"There is no current Model"
ElseIfNot mdl.IsKindOf(PdPDM.cls_Model) Then
MsgBox"The current model is not an Physical Data model."
Else
ProcessFolder mdl
EndIf
'This routine copy name into code for each table, each column and each view
'of the current folder
Privatesub ProcessFolder(folder)
Dim Tab 'running table
foreach Tab in folder.tables
ifnot tab.isShortcut then
tab.comment = tab.name
Dim col 'running column
foreach col in tab.columns
col.comment= col.name
next
endif
next
Dim view 'running view
foreach view in folder.Views
ifnot view.isShortcut then
view.comment = view.name
endif
next
'go into the sub-packages
Dim f 'running folder
ForEach f In folder.Packages
ifnot f.IsShortcut then
ProcessFolder f
endif
Next
end sub
仔细思索:为什么从SQL生成的脚本有Comment,可是到生成PDM时为什么没有转化成功呢?是否Comment名称不对应?
于是将原来的COMMENT加上COLNNAME,同时在下面的SQL语句中增加一列与COMMENT相同的值:
(select convert(varchar(8000), value) from ::fn_listextendedproperty(NULL, 'user', u.name, 'table', o.name, 'column', c.name) where name = 'MS_Description') as colnF,
如下图:
这样,Name列和Comment同时生成,终于OK!

Stored procedures are precompiled SQL statements in MySQL for improving performance and simplifying complex operations. 1. Improve performance: After the first compilation, subsequent calls do not need to be recompiled. 2. Improve security: Restrict data table access through permission control. 3. Simplify complex operations: combine multiple SQL statements to simplify application layer logic.

The working principle of MySQL query cache is to store the results of SELECT query, and when the same query is executed again, the cached results are directly returned. 1) Query cache improves database reading performance and finds cached results through hash values. 2) Simple configuration, set query_cache_type and query_cache_size in MySQL configuration file. 3) Use the SQL_NO_CACHE keyword to disable the cache of specific queries. 4) In high-frequency update environments, query cache may cause performance bottlenecks and needs to be optimized for use through monitoring and adjustment of parameters.

The reasons why MySQL is widely used in various projects include: 1. High performance and scalability, supporting multiple storage engines; 2. Easy to use and maintain, simple configuration and rich tools; 3. Rich ecosystem, attracting a large number of community and third-party tool support; 4. Cross-platform support, suitable for multiple operating systems.

The steps for upgrading MySQL database include: 1. Backup the database, 2. Stop the current MySQL service, 3. Install the new version of MySQL, 4. Start the new version of MySQL service, 5. Recover the database. Compatibility issues are required during the upgrade process, and advanced tools such as PerconaToolkit can be used for testing and optimization.

MySQL backup policies include logical backup, physical backup, incremental backup, replication-based backup, and cloud backup. 1. Logical backup uses mysqldump to export database structure and data, which is suitable for small databases and version migrations. 2. Physical backups are fast and comprehensive by copying data files, but require database consistency. 3. Incremental backup uses binary logging to record changes, which is suitable for large databases. 4. Replication-based backup reduces the impact on the production system by backing up from the server. 5. Cloud backups such as AmazonRDS provide automation solutions, but costs and control need to be considered. When selecting a policy, database size, downtime tolerance, recovery time, and recovery point goals should be considered.

MySQLclusteringenhancesdatabaserobustnessandscalabilitybydistributingdataacrossmultiplenodes.ItusestheNDBenginefordatareplicationandfaulttolerance,ensuringhighavailability.Setupinvolvesconfiguringmanagement,data,andSQLnodes,withcarefulmonitoringandpe

Optimizing database schema design in MySQL can improve performance through the following steps: 1. Index optimization: Create indexes on common query columns, balancing the overhead of query and inserting updates. 2. Table structure optimization: Reduce data redundancy through normalization or anti-normalization and improve access efficiency. 3. Data type selection: Use appropriate data types, such as INT instead of VARCHAR, to reduce storage space. 4. Partitioning and sub-table: For large data volumes, use partitioning and sub-table to disperse data to improve query and maintenance efficiency.

TooptimizeMySQLperformance,followthesesteps:1)Implementproperindexingtospeedupqueries,2)UseEXPLAINtoanalyzeandoptimizequeryperformance,3)Adjustserverconfigurationsettingslikeinnodb_buffer_pool_sizeandmax_connections,4)Usepartitioningforlargetablestoi


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 English version
Recommended: Win version, supports code prompts!

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.
