When I run
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
I will get a list of indexes having the same object_id
, but not necessarily with the same name.
Should not all indexes with the same object_id
have the same name?
Best Answer
The
Object_ID
belongs to the object the index belongs to, such as an indexed view or a table.When you look at the
object_id
in thesys.indexes
documentationIf you want to uniquely identify the index you need the
Object_ID
+index_id
columns or theindex_id
for a specificobject_id
.To verify this, you can add the
OBJECT_NAME()
function to your query