2010-12-03 57 views

回答

3

你的問題有點不清楚。這將返回至少有一個索引的所有表。

select DISTINCT OBJECT_NAME(object_id) 
from sys.indexes 
where type<>0 

或者SQL Server 2000的

select DISTINCT OBJECT_NAME(id) 
from sysindexes 
where indid<>0 
+0

Upvoting。他在SQL 2000上,所以你給出了唯一能爲他工作的答案。 – DataWriter 2010-12-03 14:05:04

2
select object_name(object_id),* from sys.indexes where type <> 0 

這將返回你可以在你的數據庫中找到所有的索引。但要小心,它也列出了系統表。

+0

這也將包括在所有(堆)沒有索引的表。這些類型具有`0` – 2010-12-03 13:34:29

+0

@編輯並更正以顯示來自sys.indexes – 2010-12-03 13:36:08

1

sys.indexes DMV應該有你要找的內容:

SELECT TableName = object_name(Object_Id) 
    , IndexName = Name 
    , IndexType = Type_Desc 

FROM sys.indexes 

的Type_Desc欄會告訴你無論你是在尋找一個堆,聚簇索引或非聚簇索引。

加入到SYS.TABLES將限制的結果,用戶表,並留下了系統表:

SELECT TableName = st.Name 
    , IndexName = si.name 
    , IndexType = si.type_desc 
    FROM SYS.indexes si 
    JOIN SYS.tables st 
    ON si.object_id = st.object_id