2014-01-17 20 views
1

我正在Sybase 15 SQL中使用存儲過程。我想確定一個臨時#table的索引。通常的技術在永久桌子上工作,但不在臨時桌子上工作:如何查找Sysbase中#table中是否存在索引?

--look for an index on a temporary table 

create table #T1(duff int) 

create index idx99 on #T1(duff) 

select * from sysindexes where name = 'idx99' --returns null rows ! 

--Look for an index on a permanent table 

create table T1(duff int) 

create index idx99 on T1(duff) 

select * from sysindexes where name = 'idx99' --returns a row. OK for perm table. 

任何想法?

鮑勃

+0

這可能適合在這裏很好,我想:http://stackoverflow.com/questions/1468183/how-i-can-find-the-list-of-sybase-indexes-for-a-given - 數據庫 – LWNirvana

+0

@LWNirvana它很近。主要區別在於臨時表將其信息保存在臨時數據庫中。 –

+0

@ user3041581嗨,我注意到你還沒有接受我的答案,只是想跟進。 –

回答

5

對於#tables,查找索引查詢是一樣的正常的表,但它需要對tempdb(或者如果它不是默認的會話臨時數據庫)執行。

SELECT o.name, i.name 
FROM tempdb..sysobjects o, tempdb..sysindexes i 
WHERE o.id = i.id 
AND o.name like "#T1%" 
AND i.name like "idx99" 
+0

謝謝,這有效,如果我糾正SQL中的錯誤:第四行應該是 和o.name像「#T1%」 – user3041581

+0

TY - 修正了代碼。 –