Changes the name of a user-created object or user-defined datatype in the current database.
sp_rename objname, newname [,“index” | “column” | “partition”]
sp_rename titles, books
sp_rename "books.title", bookname
sp_rename "books.titleind", titleindex
sp_rename tid, bookid
sp_rename "titles.title_id", isbn, "index"
sp_rename "my_tab.ind1.i_part1", i_part1_rename
sp_rename "my_tab.ind1.ind1_928003306", ind1_928003306_rename, "partition"
sp_rename changes the name of a user-created object or datatype. You can change only the name of an object or datatype in the database in which you issue sp_rename.
When you are renaming a column or index, do not specify the table name in newname. See Examples 2, 3, and 5.
If a column and an index have the same name, use the [,“index” | “column”] argument, which specifies whether to rename the index or the column. In the following sample, assume that both an index and a column named idx exist:
sp_rename "t.idx", new_idx, "column" ------------- Column name has been changed. (Return status = 0) sp_rename "t.idx", new_idx, "index" ------------- Index name has been changed. (Return status = 0)
Changing an object or column name could break existing stored procedures, cached statements or other compiled objects.
sp_engine can run in sessions using chained transaction mode if there are no open transactions.
You cannot change the names of system objects and system datatypes.
You must be the object owner to execute sp_rename. Permission checks do not differ based on the granular permissions settings.
Use the setuser command to assume another database user’s identity to rename objects owned by other users.
Values in event and extrainfo columns from the sysaudits table are:
Information | Values |
---|---|
Event | 38 |
Audit option | exec_procedure |
Command or access audited | Execution of a procedure |
Information in extrainfo |
|