• 00
  • :
  • 00
  • :
  • 00

PowerDesigner 16.5对SQL Server 2012 生成数据库时"不支持扩展属性"问题

 

团队合作设计一套系统数据模型,创建了PDM后,Table、View、Store Procedure等都创建好了,且创建了多个Schema方便管理这些数据库对象,但Table、view、Column等对象有Comment时(用来在团队不同成员间共享描述信息)

生成数据库时会得到一个提示"不支持扩展属性,或对象不存在",分析发现异常在类似以下语句:

复制代码
ifexists
(
select1from
sys.extended_properties p
where
      p.major_id =object_id
('Environment.Resource'
)
  and
p.minor_id
=
(
select
c.column_id
from
sys.columns c
where
c.
object_id=
p.major_id
and
c.name
=
'ResourceCode'
)
)
begin
execute
sp_dropextendedproperty 'MS_Description'
,
   
'user', 'Environment', 'table', 'Resource', 'column', 'ResourceCode'
end
execute
sp_addextendedproperty 'MS_Description'
,
   
'资源编码'
,
   
'user', 'Environment', 'table', 'Resource', 'column', 'ResourceCode'
go
复制代码

分析原因,发现是由于采用了Schema(上述代码中的Environment),所以sp_addextendedproperty存储过程的第三个参数就应该是SCHEMA而不是user。查询相关资料发现以上SQL语句是基于Powerdesigner自带的对应的.xdb文件生成的,如下图是Column注释信息的SQL代码模板,对应的xdb模板文件存放在powerdesigner安装路径的Sybase\PowerDesigner 16\Resource Files\DBMS\sqlsv2012.xdb

如上图,每个Column的Comment信息均通过以上代码模板生成,所以只需要修改代码模板(将sp_addextendedproperty的第三个参数值由user修改为schema即可)即可让所有对象的Comment生成语句得到修正。

注:在win7以上系统中需要使用管理员权限运行powerdesigner才能将修改后的模板文件保存。

 

摘自:http://www.cnblogs.com/xqyi/p/3937769.html

 

补充:

image

 

ColumnContent修改为:

image

 

Value修改为:

[if exists (select 1 from  sys.extended_properties
           where major_id = object_id('[%QUALIFIER%]%TABLE%') and minor_id = 0)
begin 
   [%OWNER%?[.O:[execute ][exec ]]sp_dropextendedproperty [%R%?[N]]'MS_Description',  
   [%R%?[N]]'schema', [%R%?[N]]%.q:OWNER%, [%R%?[N]]'table', [%R%?[N]]%.q:TABLE% 
:declare @CurrentUser sysname 
select @CurrentUser = SCHEMA_NAME() 
[.O:[execute ][exec ]]sp_dropextendedproperty [%R%?[N]]'MS_Description',  
   [%R%?[N]]'schema', [%R%?[N]]@CurrentUser, [%R%?[N]]'table', [%R%?[N]]%.q:TABLE% 
] 
end 


][%OWNER%?[.O:[execute ][exec ]]sp_addextendedproperty [%R%?[N]]'MS_Description',  
   [%R%?[N]]%.q:COMMENT%, 
   [%R%?[N]]'schema', [%R%?[N]]%.q:OWNER%, [%R%?[N]]'table', [%R%?[N]]%.q:TABLE% 
:select @CurrentUser = SCHEMA_NAME()
[.O:[execute ][exec ]]sp_addextendedproperty [%R%?[N]]'MS_Description',  
   [%R%?[N]]%.q:COMMENT%, 
   [%R%?[N]]'schema', [%R%?[N]]@CurrentUser, [%R%?[N]]'table', [%R%?[N]]%.q:TABLE% 
]

image

Values修改为:

[if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('[%QUALIFIER%]%TABLE%')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = %.q:COLUMN%)
)
begin
   [%OWNER%?[.O:[execute ][exec ]]sp_dropextendedproperty [%R%?[N]]'MS_Description', 
   [%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 = SCHEMA_NAME()
[.O:[execute ][exec ]]sp_dropextendedproperty [%R%?[N]]'MS_Description', 
   [%R%?[N]]'schema', [%R%?[N]]@CurrentUser, [%R%?[N]]'table', [%R%?[N]]%.q:TABLE%, [%R%?[N]]'column', [%R%?[N]]%.q:COLUMN%
]
end


][%OWNER%?[.O:[execute ][exec ]]sp_addextendedproperty [%R%?[N]]'MS_Description', 
   [%R%?[N]]%.q:COMMENT%,
   [%R%?[N]]'schema', [%R%?[N]]%.q:OWNER%, [%R%?[N]]'table', [%R%?[N]]%.q:TABLE%, [%R%?[N]]'column', [%R%?[N]]%.q:COLUMN%
:select @CurrentUser = SCHEMA_NAME()
[.O:[execute ][exec ]]sp_addextendedproperty [%R%?[N]]'MS_Description', 
   [%R%?[N]]%.q:COMMENT%,
   [%R%?[N]]'schema', [%R%?[N]]@CurrentUser, [%R%?[N]]'table', [%R%?[N]]%.q:TABLE%, [%R%?[N]]'column', [%R%?[N]]%.q:COLUMN%
]

这个是表的

其他类型同理,主要修改Values值中的user为schema,和select @CurrentUser = User_NAME() 修改为 select @CurrentUser = SCHEMA_NAME()

posted @ 2015-07-01 16:37  Garson_Zhang  阅读(1815)  评论(0编辑  收藏  举报