All for Joomla All for Webmasters

SQL RENAME TABLE

SQL RENAME TABLE syntax is used to change the name of a table. Sometimes, we choose non-meaningful name for the table. So it is required to be changed.

Let’s see the syntax to rename a table from the database.

  1. ALTER TABLE table_name
  2. RENAME TO new_table_name;

Optionally, you can write following command to rename the table.

  1. RENAME old_table _name To new_table_name;

Let us take an example of a table named “STUDENTS”, now due to some reason we want to change it into table name “ARTISTS”.

Table1: students

Name Age City
Amrita gill 25 Amritsar
Amrender sirohi 22 Ghaziabad
Divya khosla 20 Delhi

You should use any one of the following syntax to RENAME the table name:

  1. ALTER TABLE STUDENTS
  2. RENAME TO ARTISTS;

Or

  1. RENAME STUDENTS TO ARTISTS;
  2. After that the table “students” will be changed into table name “artists”
PinIt
submit to reddit

Leave a Reply

Top