HiveBrain v1.2.0
Get Started
← Back to all entries
snippetsqlMinor

How to INSERT row in another database/schema in MySQL

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
insertdatabasemysqlanotherhowrowschema

Problem

Let's say I have the following database/schema setup with the following tables:

SCHEMA_1 (default):
        TABLE_1

    SCHEMA_2:
        TABLE_2


How do I insert rows in another schema's table? The following does not seem to work:

INSERT INTO TABLE_2 (...) VALUES(...)


How is it possible to insert rows in another another schema?

Solution

It should be fully qualified table name means DatabaseName.TableName
In your case it will be

Insert into schema1.table1 (select * from schema2.table2);


This will insert all rows from schema2.table2 to schema1.table1

Code Snippets

Insert into schema1.table1 (select * from schema2.table2);

Context

StackExchange Database Administrators Q#16302, answer score: 2

Revisions (0)

No revisions yet.