使用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' 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 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
選擇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 = 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
點擊run,導出的表注釋效果如下
PowerDesigner 15的下載鏈接: https://pan.baidu.com/s/1ryohBB9RSvKbzxjjaCs69g 提取碼: r54q