Fix Error “Either the parameter @objname is ambiguous or the claimed @objtype (INDEX) is wrong” in SQL Server

If you’re getting SQL Server error Msg 15248 that reads something like “Either the parameter @objname is ambiguous or the claimed @objtype (INDEX) is wrong’“, it appears that you’re trying to perform an operation on an index, but you’ve got the naming syntax slightly wrong. Perhaps you’re trying to rename it.

When we do stuff like rename an index, we need to include the table name when referring to the existing index. It’s possible that you’ve not included this in your code.

To fix this issue, be sure to include the table name.

Example of Error

First, here’s an example of code that produces the error:

EXEC sp_rename 
    @objname = N'dbo.IX_Employees_HireDate', 
    @newname = N'IX_Employees_FiredDate', 
    @objtype = N'INDEX';

This results in the following error message:

Msg 15248, Level 11, State 1, Procedure sp_rename, Line 326
Either the parameter @objname is ambiguous or the claimed @objtype (INDEX) is wrong.

This error occurred because I didn’t provide the table name in the name for @objname. I provided the schema name, but not the table name. The table name must be inserted in between the schema name and the index name.

The following will also cause an error:

EXEC sp_rename 
    @objname = N'IX_Employees_HireDate', 
    @newname = N'IX_Employees_FiredDate', 
    @objtype = N'INDEX';

In this case I omitted the schema name and the table name, but the error occurred because I omitted the table name.

Solution

As mentioned, we need to include the table name when referring to the existing index. As Microsoft states:

If the object to be renamed is an index, object_name must be in the form table.index or schema.table.index

So, we have the option of including the schema name, but we must provide the table name (and the index name of course).

Example:

EXEC 
    sp_rename @objname = N'dbo.Employees.IX_Employees_HireDate', 
    @newname = 'IX_Employees_FiredDate', 
    @objtype = 'INDEX';

Output:

Caution: Changing any part of an object name could break scripts and stored procedures.

This time it worked successfully.

Let’s rename it back, but this time we’ll omit the schema name:

EXEC 
    sp_rename @objname = N'Employees.IX_Employees_FiredDate', 
    @newname = 'IX_Employees_HireDate', 
    @objtype = 'INDEX';

Output:

Caution: Changing any part of an object name could break scripts and stored procedures.

This also worked successfully. That’s because, although the table name and index name are required, the schema name is optional.