Introductiuon
In SQL, Creating and inserting data is important but maintaining databases are also important. Sometimes user are not happy with the current name of the table and wants to rename them according to needs.
CAUTION : Before committing to any change, user should double check that renaming the table will not make or break other components of database like stored procedures, views, etc.
Different database engines use different ways of renaming table, some uses inbuilt function, some uses inbuilt stored procedures.
Below we will show you how to handle Renaming of table according to different database engines
SQL Server
To rename a table in SQL server , user have inbuilt stored procedure named ‘sp_rename‘.
To change the table name, execute sp_rename procedure with old_table_name and new_table_name
EXEC sp_name 'old_table_name' , 'new_table_name' ;
MYSQL
In MYSQL, user just use RENAME TABLE to rename table as there are no stored procedures for this operation
RENAME TABLE old_table_name TO new_table_name;
POSTGRES
In Postgres user have to stick to ALTER TABLE and RENAME TO clause
ALTER TABLE old_table_name RENAME TO new_table_name ;
After Renaming the table user should refresh to see the newly made changes.
Thanks For Reading!
Source: Microsoft T-SQL
Learn all about SQL Basics here.