Android Question copy a table from one database to another

Mahares

Expert
Licensed User
Longtime User
But the number and names of the table fields are not known and may change, so I cannot use this method.
Another option different from @jahswant who will be busy momentarily watching his country battle Brazil in the World Cup would be to:
1. You open your first database db1
2. Attach db1 to the second database db2 using the ATTACH DATABASE statement
3. Create the table t2 in the second database like this:
B4X:
strQuery=$"CREATE TABLE IF NOT EXISTS db2.t2 AS SELECT col1, col3, col4, col7
    FROM t1"$ 
    SQL.ExecNonQuery(strQuery)
If you need more clarification, come back.
 
Last edited:
Upvote 0

Rasoull

Member
Another option different from @jahswant who will be busy momentarily watching his country battle Brazil in the World Cup would be to:
1. You open your first database db1
2. Attach db1 to the second database db2 using the ATTACH DATABASE statement
3. Create the table t2 in the second database like this:
B4X:
strQuery=$"CREATE TABLE IF NOT EXISTS db2.t2 AS SELECT col1, col3, col4, col7
    FROM t1"$
    SQL.ExecNonQuery(strQuery)
If you need more clarification, come back.
Thank you
If I attach the databases,
The data of common fields in the previous table does not change?
 
Upvote 0
Top