当我跑
SELECT
count(object_id) AS count,
object_id,
min(name) as name1,
max(name) AS name2
FROM
sys.indexes
GROUP BY object_id HAVING COUNT(*) > 1 ORDER BY count
我将获得具有相同object_id
但不一定具有相同名称的索引列表。
不应该所有具有相同名称的索引object_id
都具有相同的名称吗?
当我跑
SELECT
count(object_id) AS count,
object_id,
min(name) as name1,
max(name) AS name2
FROM
sys.indexes
GROUP BY object_id HAVING COUNT(*) > 1 ORDER BY count
我将获得具有相同object_id
但不一定具有相同名称的索引列表。
不应该所有具有相同名称的索引object_id
都具有相同的名称吗?
Object_ID
属于索引所属的对象,例如索引视图或表。当您查看文档
object_id
中的sys.indexes
如果要唯一标识索引,则需要
Object_ID
+index_id
列或index_id
特定的object_id
.要验证这一点,您可以将该
OBJECT_NAME()
函数添加到您的查询中