SQL Rename Table

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     |