How to copy data from Database to another Database?

Viewed 73

I have this structure:

Database1
New(table)
--categories(column)
----id - name - parent_id - created_at - updated_at

Database2
Old(table)
--categories(column)
----id - category - parent - created_at - updated_at

How can I copy the data of the categories from Database1 to Database2 via SQL?

3 Answers

Try this code

INSERT INTO Database1.new_table 
SELECT id,category as name,parent as parent_id,created_at,updated_at 
       FROM Database2.old_table

This query for copy database with current datetime

INSERT INTO Database1.new_table 
SELECT id,category as name,parent as parent_id,
       now() as created_at,now() as updated_at 
FROM Database2.old_table
INSERT INTO Database1.New SELECT * FROM Database2.old 

User should have read access on Database2.old and write on Database1.new

INSERT INTO DATABASE2.Old(ID, CATEGORY, PARENT, CREATED_AT, UPDATED_AT) 
SELECT ID, NAME, PARENT_ID, CREATED_AT, UPDATED_AT
FROM DATABASE1.New

This will do it

Related