Either the parameter @objname is ambiguous or the claimed @objtype (INDEX) is wrong
Asked Answered
D

2

5

With SQL Server 2016 when I run this:

SELECT * 
FROM sys.indexes 
WHERE name = 'idx_Parts_PartNum'

There is one result. As expected. But when on the same DB I run:

    exec sp_rename N'idx_Parts_PartNum', N'ux_Parts_PartNum', N'INDEX'

I get this error:

Either the parameter @objname is ambiguous or the claimed @objtype (INDEX) is wrong.

What can cause this error given that the first query shows this index name is correct?

I've Googled with no luck. My index name doesn't contain either invalid characters or a reserved word.

Note: this was created as a unique index, not a unique constraint.

I can rename the index using SQL Server Management Studio without error.

Disclose answered 3/12, 2020 at 16:17 Comment(0)
P
6

You need to give the full path of the index, as shown in the example in the documentation:

CREATE TABLE dbo.YourTable (ID int);
GO

CREATE UNIQUE INDEX IX_YourIndex ON dbo.YourTable (ID);
GO

EXEC sp_rename N'dbo.YourTable.IX_YourIndex',N'UX_YourIndex','INDEX'; --Schema, Table, Index
GO

DROP TABLE dbo.YourTable;
Pamphylia answered 3/12, 2020 at 16:21 Comment(0)
L
0

This worked for me , i was missing the table when renaming the index.

USE database ;
GO
EXEC
 sp_rename N'Schema.Table.old_INDEX',
 N'new_INDEX', 
N'INDEX' ;
GO
Layman answered 29/3, 2022 at 19:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.