您的位置:首页 > 数据库

PowerDesign 16.0 生成的SQL Server2000 数据库脚本时MS_Description不存在的问题解决

2017-01-09 16:18 295 查看
根据网上查询到的资料,找到了解决方法,原文出自:http://www.cnblogs.com/24tt/p/5047257.html

PowerDesign 16.0 生成的Script语句,Sql2000内,带字段备注的语句执行时存在如下错误:

PowerDesigner 无法更新或删除属性。“某某”的属性 MS_Description不存在。

MSSQLSRV2000::Script\Objects\Column\ColumnComment

Modified Column ColComment

修改Column ColumnComment模板 路径是 Database -> Edit Current DBMS 窗体 General 选项卡 下 Script -> Objects -> Column -> ColumnComment

实际上是默认生成语句存在判断错误:默认的如下():

[if exists (select 1 from sysproperties where id = object_id('[%QUALIFIER%]%TABLE%') and type = 4) begin

以上判断是该表是否已存在备注,当有2个及以上备注要添加时(如C1,C2),添加到第二个备注C2,判断系统一定存在,而紧接着需要执行删除C2,因C2都没有添加过需要删除肯定会提示“无法更新或删除属性”了。sp_dropextendedproperty

因此需要修改判断,定位到精准的该字段是否有备注,有则删除,修改为如下(红色为添加部分,SQL2000测试通过):

[if exists (select 1

from sysproperties where id = object_id('[%QUALIFIER%]%TABLE%') and smallid in(select colid from syscolumns where id = object_id('[%QUALIFIER%]%TABLE%') and name = %.q:COLUMN% and number = 0) and name='MS_Description' and type = 4 ) begin

最后贴出完整的代码:

[if exists (select 1
from sysproperties
where id = object_id('[%QUALIFIER%]%TABLE%')
and smallid in(select colid
from    syscolumns
where    id = object_id('[%QUALIFIER%]%TABLE%')
and name = %.q:COLUMN% and
number = 0) and name='MS_Description'  and type = 4 )
begin
[%OWNER%?[.O:[execute ][exec ]]sp_dropextendedproperty [%R%?
]'MS_Description',
[%R%?
]'user', [%R%?
]%.q:OWNER%, [%R%?
]'table', [%R%?
]%.q:TABLE%, [%R%?
]'column', [%R%?
]%.q:COLUMN%
:declare @CurrentUser sysname
select @CurrentUser = user_name()
[.O:[execute ][exec ]]sp_dropextendedproperty [%R%?
]'MS_Description',
[%R%?
]'user', [%R%?
]@CurrentUser, [%R%?
]'table', [%R%?
]%.q:TABLE%, [%R%?
]'column', [%R%?
]%.q:COLUMN%
]

end

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


该代码经过测试,暂时没问题。



这是修改位置
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐