Rename Table in SQL
? RENAME TABLE in SQL
The RENAME TABLE statement is used to rename an existing table to a new name.
? Syntax (MySQL, PostgreSQL, SQL Server, etc.)
? MySQL:
RENAME TABLE old_table_name TO new_table_name;Example:
RENAME TABLE employees TO staff;? PostgreSQL:
ALTER TABLE old_table_name RENAME TO new_table_name;Example:
ALTER TABLE employees RENAME TO staff;? SQL Server (T-SQL):
EXEC sp_rename 'old_table_name', 'new_table_name';Example:
EXEC sp_rename 'employees', 'staff';?? Notes:
Table structure and data remain unchanged.
You must have ALTER permission on the table.
If the table is referenced by foreign keys or views, update them accordingly.
Would you like a full example from table creation to renaming across databases?