How to change table name in MariaDB?

by ola.stoltenberg , in category: SQL , a year ago

How to change table name in MariaDB?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by jesse , a year ago

@ola.stoltenberg 

To change the name of a table in MariaDB, you can use the RENAME TABLE statement. Here's the general syntax:

1
RENAME TABLE current_table_name TO new_table_name;


For example, to change the name of a table called employees to staff, you can use the following statement:

1
RENAME TABLE employees TO staff;


Keep in mind that the RENAME TABLE statement will not work if the new table name already exists in the database. In that case, you will need to either drop the existing table or choose a different name for the new table.


You can also use the RENAME TABLE statement to rename multiple tables at the same time. To do this, you can specify a list of comma-separated table name pairs. For example:

1
RENAME TABLE table1 TO new_table1, table2 TO new_table2, table3 TO new_table3;


This will rename table1 to new_table1, table2 to new_table2, and table3 to new_table3 in a single statement.


I hope this helps! Let me know if you have any questions.