使用PowerDesigner 15生成SQL Server中文注释

 

问题描述

使用Power DesignerPD)生成的SQL脚本创建SQL Server database后,表和字段的Description都变成了乱码,如????Google了一些相关文章后,没有很好的解决方法,要么是对MySql的,要么是对Oracle的,没有发现SQL Server 的。

解决方法

开始以为是PD生成的脚本文件编码不对,修改编码为简体中文GB2312也不行;修改数据库的CollationChinese-PRC-CI-AS也不行。后来直接在SQL Server建测试表,添加注释,导出脚本,分别如下所示:

PD生成的注释:

execute sp_addextendedproperty 'MS_Description',

   '附件',

   'user', 'dbo', 'table', 'WF_Attchment'

go

 

execute sp_addextendedproperty 'MS_Description',

   '附件ID',

   'user', 'dbo', 'table', 'WF_Attchment', 'column', 'AttchmentID'

Go

SQL Server生成的注释:

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'附件ID' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'WF_Attchment', @level2type=N'COLUMN',@level2name=N'AttchmentID'

GO

 

PD生成的脚本同SQL Server导出的脚本比较后,发现在赋值给注释的Value上了一个N。找到了问题的根源,这下就好办了,我们需要在PD里进行处理。

1.       修改数据库模型的语言属性,位置在PD|Database|Gernate Datebase|Format,修改语言为UTF-8,如下图所示:

2.       修改生成的脚本的注释,修改的地方在:

tools-->resources-->dbms-->sql server 2008打开DBMS属性窗口,在general选项卡中选择Microsoft SQL Server 2008-->script-->objects,可以修改Objects下的Table注释-表注释和Column注释-字段注释,

 

/表注释/

/默认表注释/

[%OWNER%?[.O:[execute ][exec ]]sp_addextendedproperty [%R%?[N]]'MS_Description',

   [%R%?[N]]%.q:COMMENT%,

   [%R%?[N]]'user', [%R%?[N]]%.q:OWNER%, [%R%?[N]]'table', [%R%?[N]]%.q:TABLE%

:declare @CurrentUser sysname

select @CurrentUser = user_name()

[.O:[execute ][exec ]]sp_addextendedproperty [%R%?[N]]'MS_Description',

   [%R%?[N]]%.q:COMMENT%,

   [%R%?[N]]'user', [%R%?[N]]@CurrentUser, [%R%?[N]]'table', [%R%?[N]]%.q:TABLE%

]

/修改后的表注释/

[%OWNER%?[.O:[execute ][exec ]]sp_addextendedproperty [%R%?[N]]'MS_Description',

   [[N]]%.q:COMMENT%,

   [%R%?[N]]'user', [%R%?[N]]%.q:OWNER%, [%R%?[N]]'table', [%R%?[N]]%.q:TABLE%

:declare @CurrentUser sysname

select @CurrentUser = user_name()

[.O:[execute ][exec ]]sp_addextendedproperty [%R%?[N]]'MS_Description',

   [[N]]%.q:COMMENT%,

   [%R%?[N]]'user', [%R%?[N]]@CurrentUser, [%R%?[N]]'table', [%R%?[N]]%.q:TABLE%

]

////////////////////////

/字段注释/

 

/默认字段注释/

[%OWNER%?[.O:[execute ][exec ]]sp_addextendedproperty [%R%?[N]]'MS_Description',

   [%R%?[N]]%.q:COMMENT%,

   [%R%?[N]]'user', [%R%?[N]]%.q:OWNER%, [%R%?[N]]'table', [%R%?[N]]%.q:TABLE%, [%R%?[N]]'column', [%R%?[N]]%.q:COLUMN%

:declare @CurrentUser sysname

select @CurrentUser = user_name()

[.O:[execute ][exec ]]sp_addextendedproperty [%R%?[N]]'MS_Description',

   [%R%?[N]]%.q:COMMENT%,

   [%R%?[N]]'user', [%R%?[N]]@CurrentUser, [%R%?[N]]'table', [%R%?[N]]%.q:TABLE%, [%R%?[N]]'column', [%R%?[N]]%.q:COLUMN%

]

/修改后的字段注释/

[%OWNER%?[.O:[execute ][exec ]]sp_addextendedproperty [%R%?[N]]'MS_Description',

   [[N]]%.q:COMMENT%,

   [%R%?[N]]'user', [%R%?[N]]%.q:OWNER%, [%R%?[N]]'table', [%R%?[N]]%.q:TABLE%, [%R%?[N]]'column', [%R%?[N]]%.q:COLUMN%

:declare @CurrentUser sysname

select @CurrentUser = user_name()

[.O:[execute ][exec ]]sp_addextendedproperty [%R%?[N]]'MS_Description',

   [[N]]%.q:COMMENT%,

   [%R%?[N]]'user', [%R%?[N]]@CurrentUser, [%R%?[N]]'table', [%R%?[N]]%.q:TABLE%, [%R%?[N]]'column', [%R%?[N]]%.q:COLUMN%

]

修改字段注释还有一种方法,如下所示:

/修改后的字段注释/

[%OWNER%?[.O:[execute ][exec ]]sp_addextendedproperty [%R%?[N]]'MS_Description',

   [[N]]%.q:COMMENT%,

   [%R%?[N]]'schema', [%R%?[N]]%.q:OWNER%, [%R%?[N]]'table', [%R%?[N]]%.q:TABLE%, [%R%?[N]]'column', [%R%?[N]]%.q:COLUMN%

:declare @CurrentUser sysname

select @CurrentUser = user_name()

[.O:[execute ][exec ]]sp_addextendedproperty [%R%?[N]]'MS_Description',

   [[N]]%.q:COMMENT%,

   [%R%?[N]]'schema', [%R%?[N]]@CurrentUser, [%R%?[N]]'table', [%R%?[N]]%.q:TABLE%, [%R%?[N]]'column', [%R%?[N]]%.q:COLUMN%

]

 

你可能感兴趣的:(powerDesigner)