1
Reply

How to transfer a table from one schema to another?

Sapna Malik

Sapna Malik

13y
3.9k
0
Reply

    To transfer a table from one schema to another in MySQL, you can use the CREATE TABLE statement with the AS keyword to create a new table in the target schema based on the structure and data of the original table. Here are the steps:

    Open a MySQL client and connect to the MySQL server where the original schema and target schema exist.

    Select the source schema using the USE statement:
    USE original_schema;
    Create a new table in the target schema using the CREATE TABLE statement with the AS keyword:
    CREATE TABLE target_schema.new_table AS SELECT * FROM original_table;
    This statement creates a new table called new_table in the target_schema with the same structure and data as the original_table.

    (Optional) If you want to remove the original table from the source schema, you can use the DROP TABLE statement:
    DROP TABLE original_table;
    This statement deletes the original_table from the original_schema.

    That’s it! You have now transferred a table from one schema to another