RENAME command is used to set the new name of the exists table
Syntax:-
ALTER TABLE table_name RENAME TO new_table_name;
Example:-
Suppose we have an employees table
Now, we change table name employees to users.
ALTER TABLE employees RENAME TO users;
Now, get the results from the users table
SELECT * FROM users;
Output:-
+----+------------+-----------+----------------+------------+
| id | first_name | last_name | email | address |
+----+------------+-----------+----------------+------------+
| 1 | John | Tailor | john@abc.com | California |
| 2 | Rom | Tailor | rom@abc.com | California |
| 3 | Andrew | Symonds | andrew@abc.com | Sydney |
| 4 | Miacle | clerk | miacle@abc.com | sydney |
| 5 | Sachin | Tendulkar | sachin@abc.com | Mumbai |
SQL Rename Table – Interview Questions
Q 1: What does RENAME TABLE do?
Ans: It changes the name of an existing table.
Q 2: Syntax for renaming a table?
Ans: RENAME TABLE old_name TO new_name;
Q 3: Does renaming delete data?
Ans: No, all data remains intact.
Q 4: Can multiple tables be renamed?
Ans: Yes, some databases support renaming multiple tables.
Q 5: Is RENAME TABLE faster than recreating?
Ans: Yes, it is more efficient and safer.
SQL Rename Table – Objective Questions (MCQs)
Q1. Which SQL command is used to rename a table?
Q2. What is the correct syntax to rename a table?
Q3. Renaming a table affects:
Q4. RENAME TABLE is part of which SQL category?
Q5. Which permission is required to rename a table?