欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

PowerDesigner16生成SQL2005列注释的方法

程序员文章站 2022-06-04 23:05:16
powerdesigner界面-tools-resources-dbms,点击左上角的new,选择copy from templete,如果你的数据库是sql server...

powerdesigner界面-tools-resources-dbms,点击左上角的new,选择copy from templete,如果你的数据库是sql server 2005,选择系统自带的sql server 2005,如果是sql server 2008,选择系统自带的sqlsv2k8.xdb。

如果你想修改默认的选项,可以直接选择sql server 2005或者08.

选择script---objects---column---sqllistquery

修改为如下的代码:


{owner, table, s, column, dttpcode, length, size, prec, compute, notnull, identity, domain, default, extidentityseedinc, comment,colnname, extcollation, extidtnotforreplication, extdeftconstname, 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), p.value),
    convert(varchar(8000), p.value),
    c.collation_name,
    case (i.is_not_for_replication) when 1 then 'true' else 'false' end,
    d.name,
    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)
    left outer join [%catalog%.]sys.extended_properties p on (p.major_id = o.object_id and p.minor_id = c.column_id and p.class =1)
where
   o.type in ('u', 's', 'v')

[  and u.name = %.q:owner%]
[  and o.name=%.q:table%]
order by 1, 2, 3

其实只是增加了上面代码中的黄色部分,就可以了。测试后,ok。
其实我还想修改表注释,就是在显示英文表名的地方显示出中文含义,如acccount(账户表)
但是修改了table中的很多地方都没有成功,不知道大家有没有知道如何修改的,如果知晓请告知。