查询以获取在特定数据库中具有索引的表

时间:2010-12-03 13:26:01

标签: sql sql-server

任何人都可以在sql server中为我提供查询,以便为特定数据库提取已经完成索引的表....

3 个答案:

答案 0 :(得分: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

答案 1 :(得分:2)

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

这将返回数据库中可用的所有索引。但要注意,它还列出了系统表。

答案 2 :(得分: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