Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Command for copying table

Tags:

sql

mysql

What is the SQL command to copy a table from one database to another database? I am using MySQL and I have two databases x and y. Suppose I have a table in x called a and I need to copy that table to y database. Sorry if the question is too novice.

Thanks.

like image 447
Omnipotent Avatar asked Sep 25 '08 07:09

Omnipotent


1 Answers

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

like image 76
cagcowboy Avatar answered Oct 10 '22 22:10

cagcowboy