Use sp_rename to change a table’s name in SQL Server without affecting its data or constraints.
Renaming clarifies business meaning, aligns with new naming conventions, or frees a name for a replacement table. It keeps data intact and avoids the overhead of creating a new table.
The native system stored procedure sp_rename
accepts the current fully qualified table name and the desired new name. Optionally specify the object type.
EXEC sp_rename
@objname = 'schema.current_table_name',
@newname = 'new_table_name',
@objtype = 'OBJECT'; -- optional but recommended
Wrap the command in a transaction, clear dependent cached plans, and update documentation. Example shows renaming Orders
to CustomerOrders
in the dbo
schema.
BEGIN TRAN;
-- 1. Rename table
EXEC sp_rename 'dbo.Orders', 'CustomerOrders', 'OBJECT';
-- 2. Refresh dependent views or procedures if needed
EXEC sp_refreshsqlmodule 'dbo.GetRecentOrders';
COMMIT;
Create a full backup, search codebase for hard-coded table names, update ORM mappings, and notify teams. Always run tests in staging first.
Do not omit the schema prefix—SQL Server may look in dbo
by default and miss the intended table. Also, avoid renaming during high-traffic windows to prevent plan cache churn.
Yes. Run sp_rename
again with the old name or execute ROLLBACK
if you are still inside the same transaction.
The table’s internal object_id stays the same, so indexes, triggers, and constraints remain intact. Only the metadata name changes.
sp_rename
cannot move a table between schemas. To change schema, use ALTER SCHEMA target_schema TRANSFER source_schema.table_name;
after (or instead of) renaming.
Yes. References use internal object IDs, so no manual change is needed.
You can run sp_rename again or restore from backup, but there is no single "undo" button once committed.
Yes. The action appears in the default trace and can be captured by extended events or a DDL trigger.