PowerDesign 16.0 生成的SQL Server2000 數據庫腳本時MS_Description不存在的問題解決

根據網上查詢到的資料,找到了解決方法,原文出自:http://www.cnblogs.com/24tt/p/5047257.htmlhtml

 

PowerDesign 16.0 生成的Script語句,Sql2000內,帶字段備註的語句執行時存在以下錯誤:測試

PowerDesigner 沒法更新或刪除屬性。「某某」的屬性 MS_Description不存在。spa

 MSSQLSRV2000::Script\Objects\Column\ColumnComment3d

Modified Column ColComment  code

修改Column ColumnComment模板   路徑是 Database -> Edit Current DBMS 窗體 General 選項卡 下 Script -> Objects -> Column -> ColumnCommenthtm

其實是默認生成語句存在判斷錯誤:默認的以下():blog

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

以上判斷是該表是否已存在備註,當有2個及以上備註要添加時(如C1,C2),添加到第二個備註C2,判斷系統必定存在,而緊接着須要執行刪除C2,因C2都沒有添加過須要刪除確定會提示「沒法更新或刪除屬性」了。sp_dropextendedproperty it

 

所以須要修改判斷,定位到精準的該字段是否有備註,有則刪除,修改成以下(紅色爲添加部分,SQL2000測試經過):io

[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%?[N]]'MS_Description', 
   [%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_dropextendedproperty [%R%?[N]]'MS_Description', 
   [%R%?[N]]'user', [%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]]'user', [%R%?[N]]%.q:OWNER%, [%R%?[N]]'table', [%R%?[N]]%.q:TABLE%, [%R%?[N]]'column', [%R%?[N]]%.q:COLUMN%
: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%
]

 

該代碼通過測試,暫時沒問題。

這是修改位置

相關文章
相關標籤/搜索