SQL - Rename Table and Database | How to rename table & database in SQL?

SQL Rename Table

Definition: 
 

  • Renaming a database  

Renaming a database in SQL refers to the process of changing the name of the entire database. This can be useful when a database needs to be rebranded or when the name of the database no longer accurately reflects its contents. Renaming a database updates the system catalogs and changes the physical database file names on disk. However, any connections to the database must be closed before renaming it, and the database must be in a single-user mode to perform the renaming operation. 

  • Renaming a table 

Renaming a table in SQL refers to the process of changing the name of a specific table within a database. This can be useful for improving the clarity of the database schema, or for correcting a misspelled or inaccurate table name. Renaming a table does not affect any data within the table or any relationships between the table and other tables. 

Renaming a database  

Method1: Direct from object explorer 

Right click on Database>Rename

Method2 

Stntax: 

ALTER DATABASE Old_Database_name MODIFY NAME =New_Database_name; 

Example: 

ALTER DATABASE Bitacloud MODIFY NAME = Bita; 

Result:

Database_Name before execution of command. 

Database_Name after execution of command.



 

limitations for changing name of database in sql: 

  • Single-User Mode: To change the name of a database in SQL Server, the database must be in single-user mode. This means that no other users or applications can be connected to the database while the rename operation is taking place. 
  • User and Application Connections: All user and application connections must be closed before renaming the database. This can be disruptive to ongoing operations, and may require downtime for affected applications. 
  • Database Replication: If the database is part of a replication topology, additional steps may be required to ensure that the replication process continues to function properly after the renaming operation. 
  • Backup and Restore: Backup and restore operations may be affected by a database rename, and may require additional steps to ensure that backups and restores continue to function properly. 
  • Linked Servers: If the database is linked to other servers, additional configuration steps may be required to ensure that the links continue to function properly after the renaming operation. 
  • Security and Permissions: Any security and permissions settings associated with the old database name will need to be updated to reflect the new database name. 

Renaming a table 

Method1 

Method2 

Syntax: 

EXEC sp_rename ‘Old Table_Name’, ‘New Table_Name’ 

Example: 

EXEC sp_rename ‘dbo.products’, ‘product’ 

Result: 

Before:- Table_Name before execution of command. 

After:- Table_Name after execution of command. 

Vijay Kashyap Algo Trading Expert

Author & Editor

Has laoreet percipitur ad. Vide interesset in mei, no his legimus verterem. Et nostrum imperdiet appellantur usu, mnesarchum referrentur id vim.