解決PowerDesigner 16 Generate Datebase For Sql2005/2008 對象名sysproperties無效的問題

在PowerDesigner 16 中生成的sql語句,在執行的時候報錯:對象名sysproperties 無效的錯誤;形成此問題的緣由是因爲Sql 200五、2008 刪除了系統表 sysproperties 而改用 sys.extended_properties 表所致 , 如下是經過建立sysproperties視圖,以及修改powerdesigner sql語句生成模板後,html

再生成數據庫SQL腳本執行,共分爲三部:sql

第一步:在Sql 2005/2008 Exec the Sql 建立View 'sysproperties'數據庫

if exists (select 1 from sysobjects where name = 'sysproperties'and xtype = 'V')
begin
    DROP VIEW sysproperties
end
    GO
    CREATE VIEW sysproperties
    AS
    SELECT A.name As TableName,
    A.id As TableID,B.Name As ColName,B.colid As ColID,
    B.xtype As ColType,C.name As PropName,C.Value As PropValue
    FROM sysobjects As A INNER JOIN syscolumns As B ON A.id = B.id
    INNER JOIN sys.extended_properties As C ON C.major_id = A.id 
    AND ( minor_id = B.colid)

第二 步: 修改Table TableComment模板 路徑是 Database -> Edit Current DBMS 窗體 General 選項卡 下 Script -> Objects -> Table -> TableCommentspa

[if exists (select 1 
from sys.extended_properties 
where major_id = object_id('[%QUALIFIER%]%TABLE%') 
and minor_id = 0 and name = 'MS_Description') 
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% 
: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% 
] 
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% 
: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% 
]

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

[if exists (select 1
from sysproperties
where TableID = object_id('[%QUALIFIER%]%TABLE%')
and ColName = %.q:COLUMN% AND PropName='MS_Description')
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%
]

修改以後 使用Generate Database 生成的SQL即可在SQL 2005/2008下執行 不在報找不到sysproperties 的錯誤。htm

本文複製來自:http://www.cnblogs.com/zhouchaoyi/archive/2012/03/07/2383509.html對象

相關文章
相關標籤/搜索