Insert values and select the data from the table mysql> INSERT INTO cricket_runs VALUES(10), (24), (38), (60), (85) So, first, we need to create a temporary table using the following statement mysql> CREATE TEMPORARY TABLE cricket_runs(runs int NOT NULL) Rename Temporary tableĪ temporary table allows us to keep temporary data, which is visible and accessible in the current session only. Here we can see that electric_items changed into gadgets. Here we are going to change electric_items into gadgets mysql> RENAME TABLE electric_items TO gadgets Syntax: ALTER TABLE old_table_name RENAME TO new_table_name The following are the syntax of the ALTER TABLE statement The ALTER TABLE statement can also be used to rename the existing table in the current database. In above output we can see that the table name invoices into payments and table name orders into sales have successfully renamed. Mysql> RENAME TABLE invoices TO payments, orders TO sales Suppose if we want to change the table name invoices into payments and table name orders into sales, execute the following statement Suppose our database “sampledb_info” having the following tables mysql> SHOW TABLES Old_table_name2 TO new_table_name2, old_table_name3 TO new_table_name3 See the below statement RENAME TABLE old_table_name1 TO new_table_name1, RENAME TABLE statement in MySQL also allows us to change more than one table name within a single statement. Now we can confirm using below SQL statementĮRROR 1146 (42S02): Table 'sampledb_info.gadgets' doesn't existĥ rows in set (0.01 sec) 4. Mysql> RENAME TABLE gadgets TO electric_items Next, execute the following syntax to change the table name mysql> USE sampledb_info Suppose we have a table named gadgets, and due to some reason, there is a need to change it into the table named electric_items. Let us understand how the RENAME TABLE statement works in MySQL through the various examples.
0 Comments
Leave a Reply. |