SQL Command for copying table SQL Command for copying table sql sql

SQL Command for copying table

If the target table doesn't exist....

CREATE TABLE dest_table AS (SELECT * FROM source_table);

If the target table does exist

INSERT INTO dest_table (SELECT * FROM source_table);

Caveat: Only tested in Oracle

If your two database are separated, the simplest thing to do would be to create a dump of your table and to load it into the second database. Refer to your database manual to see how a dump can be performed.

Otherwise you can use the following syntax (for MySQL)

INSERT INTO database_b.table (SELECT * FROM database_a.table)

Since your scenario involves two different databases, the correct query should be...

INSERT INTO Y..dest_table (SELECT * FROM source_table);

Query assumes, you are running it using X database.