最新使用PowerDesigner對SQL Server 2000資料庫作反向工程、以比較資料庫和PDM的差異的時候,經常
會從資料庫中Reverse出來一些名稱以“_WA_Sys”開頭的索引,這些索引並不是我們做資料庫設計的時候
加的,而且從企業管理器中也看不到這些索引。
但是,使用“select * from sysindexes where name like '_WA_Sys%'”語句,直接查詢sysindexes系
統表卻能夠查詢出來。
後經查詢相關技術文檔得知,名稱以“_WA_Sys”開頭的索引,其實並不是真正的索引、也不具備索引的
功能,它是SQL Server查詢最佳化工具自動建立的統計資訊(statistics)。
可是我們在PowerDesigner裡面並不需要這些統計資訊,如何才能使PD在Reverse的時候過濾掉這些統計呢
?
在PowerDesigner裡面依次點擊Tools-Resources-DBMS,開啟“List of DBMS”視窗,從中選擇Microsoft
SQL Server 2000,再點擊視窗上方的第一個按鈕“Property”,現在我們來編輯PD的Reverse行為——
從左側的TreeView中依次展開Script/Objects/Index,點擊SqlListQuery,在右面的Value大編輯框裡我
們可以看到如下SQL語句:
{OWNER ID, TABLE ID, INDEX ID, CLUSTER ID, UNIQUE ID, CIDXLIST ...}
select
u.name,
o.name,
i.name,
case(i.status & 16) when 16 then 'clustered' else '' end,
case(i.status & 2) when 2 then 'unique' else '' end,
case(k.keyno) when 1 then '' else ', ' end + c.name + case (Indexkey_Property(k.id,
k.indid, k.keyno, 'IsDescending')) when 1 then ' desc' else ' asc' end
from
sysusers u
join sysobjects o on (o.uid = u.uid)
join sysindexes i on (i.id = o.id)
join sysindexkeys k on (k.id = i.id and k.indid = i.indid)
join syscolumns c on (c.id = k.id and c.colid = k.colid)
where i.indid between 1 and 254
[ and o.name = %.q:TABLE%]
[ and u.name = %.q:SCHEMA%]
order by
1, 2, 3, k.keyno
好的,看到了嗎?在where i.indid between 1 and 254的下方加一句:
and i.name not like '%_WA_Sys%' --過濾掉SQL Server自動建立的統計資訊
就OK了。
加完之後就是現在這個樣子:
{OWNER ID, TABLE ID, INDEX ID, CLUSTER ID, UNIQUE ID, CIDXLIST ...}
select
u.name,
o.name,
i.name,
case(i.status & 16) when 16 then 'clustered' else '' end,
case(i.status & 2) when 2 then 'unique' else '' end,
case(k.keyno) when 1 then '' else ', ' end + c.name + case (Indexkey_Property(k.id,
k.indid, k.keyno, 'IsDescending')) when 1 then ' desc' else ' asc' end
from
sysusers u
join sysobjects o on (o.uid = u.uid)
join sysindexes i on (i.id = o.id)
join sysindexkeys k on (k.id = i.id and k.indid = i.indid)
join syscolumns c on (c.id = k.id and c.colid = k.colid)
where i.indid between 1 and 254
and i.name not like '%_WA_Sys%' --過濾掉SQL Server自動建立的統計資訊
[ and o.name = %.q:TABLE%]
[ and u.name = %.q:SCHEMA%]
order by
1, 2, 3, k.keyno
好了,儲存並關掉所有視窗,重新試試PD的Reverse,索引列表中是不是沒有那些統計資訊了?