简体   繁体   English

表上的自动索引

[英]Automatic index on a table

I was trying to find out if any index is created on a table, automatically.我试图找出是否在表上自动创建了任何索引。 I used this link to find indexes on Employees table which has 4 columns, namely empid, empName, salary and dept.我使用此链接查找员工表上的索引,该表有 4 列,即 empid、empName、salary 和 dept。 The query shows that table already has an index - I don't have keys on the table.查询显示该表已经有一个索引 - 我在表上没有键。 This link says that non-clustered indexes are not created automatically on a table.链接表示不会在表上自动创建非聚集索引。 So what is the type of index that is already present on Employees table ?那么,Employees 表上已经存在的索引类型是什么? Also, index name is shown as null.此外,索引名称显示为空。

Create statement and query used to find indexes on Employees table are as follows :用于在员工表上查找索引的创建语句和查询如下:

 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')

This is the output from the sys.indexes query in your question:这是您问题中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 |
+------------+------+----------+------+-----------+-----------+---------------+----------------+----------------+----------------------+-------------+-----------+-------------+-----------------+----------------------------+-----------------+------------------+------------+-------------------+-------------------+---------------------------+--------------+

Note the type_desc value is "HEAP", meaning a table without a clustered index.请注意, type_desc值为“HEAP”,表示没有聚集索引的表。 So the returned row is the table itself rather than an index.所以返回的行是表本身而不是索引。 The documentation for sys.indexes states (my emphasis): sys.indexes文档说明(我的重点):

Contains a row per index or heap of a tabular object, such as a table, view, or table-valued function包含表格对象(例如表、视图或表值函数)的每个索引或的行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM