To change a table name in SQL, the terms ALTER TABLE will be entered first, followed by the table’s original name, the keywords RENAME TO, and then the new table name.
Example
Employee Table
emp_id | emp_name | salary | dept_id | manager_id |
---|---|---|---|---|
E1 | Rahul | 15000 | D1 | M1 |
E2 | Manoj | 15000 | D1 | M1 |
E3 | James | 55000 | D2 | M2 |
E4 | Michael | 25000 | D2 | M2 |
E5 | Ali | 20000 | D10 | M3 |
E6 | Robin | 35000 | D10 | M3 |
The query to change the name of the table would be:
ALTER TABLE Employee Table
RENAME TO employee_information;
Output
employee_information
emp_id | emp_name | salary | dept_id | manager_id |
---|---|---|---|---|
E1 | Rahul | 15000 | D1 | M1 |
E2 | Manoj | 15000 | D1 | M1 |
E3 | James | 55000 | D2 | M2 |
E4 | Michael | 25000 | D2 | M2 |
E5 | Ali | 20000 | D10 | M3 |
E6 | Robin | 35000 | D10 | M3 |