sp_iqrename Procedure

Renames user-created tables, columns, indexes, constraints (unique, primary key, foreign key, and check), stored procedures, and functions.

Syntax

sp_iqrename object-name, new-name [, object-type ]

Parameters

Warning!   You must change appropriately the definition of any dependent object (procedures, functions, and views) on an object being renamed by sp_iqrename. The sp_iqrename procedure does not automatically update the definitions of dependent objects. You must change these definitions manually.

Privileges

You must have EXECUTE privilege on the system procedure. Different privileges are needed to rename specific object types as follows:
  • ALTER ANY OBJECT system privilege – You can rename any object.
  • ALTER ANY TABLE system privilege – You can rename any table, column or constraint.
  • ALTER ANY INDEX system privilege – You can rename any index, but not tables or columns.
  • REFERENCES privilege on a table – You can rename indexes of that table only.
  • ALTER privilege on the table – You can rename that table, its columns, and constraints only.
  • You own the table – You can rename any objects you own.
You must also have exclusive access to the object is required to run this procedure.

Remarks

The sp_iqrename stored procedure renames user-created tables, columns, indexes, constraints (unique, primary key, foreign key, and check), and functions.

If you attempt to rename an object with a name that is not unique for that type of object, sp_iqrename returns the message “Item already exists.”

sp_iqrename does not support renaming a view, a procedure, an event or a data type. The message “Feature not supported.” is returned by sp_iqrename, if you specify event or datatype as the object-type parameter.

You can also rename using the RENAME clause of the ALTER TABLE statement and ALTER INDEX statement.

Example

Renames the table titles owned by user shweta to books:
sp_iqrename shweta.titles, books
Renames the column id of the table books to isbn:
sp_iqrename shweta.books.id, isbn, column
Renames the index idindex on the table books to isbnindex:
sp_iqrename books.idindex, isbnindex, index
Renames the primary key constraint prim_id on the table books to prim_isbn:
sp_iqrename books.prim_id, prim_isbn, constraint
Related reference
Determining the Security Model Used by a Database