表格上的自动索引

时间:2018-08-19 08:57:22

标签: sql-server

我试图找出是否在表上自动创建了任何索引。我使用此link在Employees表上查找索引,该表具有4列,即empid,empName,salary和dept。查询显示该表已具有索引-我在表上没有键。 link表示未在表上自动创建非聚集索引。那么,Employees表中已经存在的索引类型是什么?此外,索引名称显示为空。

用于在Employees表上查找索引的创建语句和查询如下:

 Create table Employees( 
      empid int,
      empName varchar(100),
      salary int,
      dept varchar(10)
    )

   select * from sys.indexes
   where object_id = (select object_id 
                     from sys.objects where name = 'Employees')

1 个答案:

答案 0 :(得分:2)

这是您的问题中sys.indexes查询的输出:

+------------+------+----------+------+-----------+-----------+---------------+----------------+----------------+----------------------+-------------+-----------+-------------+-----------------+----------------------------+-----------------+------------------+------------+-------------------+-------------------+---------------------------+--------------+
| object_id  | name | index_id | type | type_desc | is_unique | data_space_id | ignore_dup_key | is_primary_key | is_unique_constraint | fill_factor | is_padded | is_disabled | is_hypothetical | is_ignored_in_optimization | allow_row_locks | allow_page_locks | has_filter | filter_definition | compression_delay | suppress_dup_key_messages | auto_created |
+------------+------+----------+------+-----------+-----------+---------------+----------------+----------------+----------------------+-------------+-----------+-------------+-----------------+----------------------------+-----------------+------------------+------------+-------------------+-------------------+---------------------------+--------------+
| 1746105261 | NULL |        0 |    0 | HEAP      |         0 |             1 |              0 |              0 |                    0 |           0 |         0 |           0 |               0 |                          0 |               1 |                1 |          0 | NULL              | NULL              |                         0 |            0 |
+------------+------+----------+------+-----------+-----------+---------------+----------------+----------------+----------------------+-------------+-----------+-------------+-----------------+----------------------------+-----------------+------------------+------------+-------------------+-------------------+---------------------------+--------------+

请注意,type_desc的值为“ HEAP”,表示没有聚集索引的表。因此,返回的行是表本身而不是索引。 documentation for sys.indexes的状态(我的重点):

  

每个索引对象或表格对象(例如表格)的都包含一行,   视图或表值函数