Sql rename table query

Sql rename table query

Blog Bustle 08/03/2020

Sql rename table query is used to change table name in database. We can rename one or more tables using single query.

sql rename table query syntax

There are two methods to change table name in database. You can use any of them. Both are correct.

1. Using rename table

RENAME TABLE table_name to new_table_name;

Rename multiple tables syntax

RENAME TABLE
table1_name to new_table1_name,
table2_name to new_table2_name,
table3_name to new_table3_name,
....
tableN_name to new_tableN_name;

2. Using alter table

ALTER TABLE table_name RENAME TO new_table_name;

For example, i have two tables class and subject in student database.

i will change class table name to classes using rename table and sql rename table query will be

rename table class to classes;

now i will change subject table name to subjects using alter table and sql rename table query will be

alter table subject
rename to subjects;

sql rename table query

Remember that first select database then run any sql query related to that database otherwise you will get 'no database selected' error.

So we can easily change table name in database using sql rename table query. Hope you like this tutorial.

Other important links

No Database Selected error

Alter query in sql

Create table sql query

Delete table sql query

Sql rename table query searches:

Tags: #mysql