Asahi
Asahi

Reputation: 13506

Android SQLite: what is the best way to create a copy of database

What is the best way to create a copy of all data from database A in database B using SQL (and not a file copy)?

Upvotes: 0

Views: 455

Answers (1)

Sunil Kumar Sahoo
Sunil Kumar Sahoo

Reputation: 53657

There is two approach check which one you prefers. but I think if possible i will follow first approach. But I have never done it.

First Approach Copy the first database and paste with some othername see following url

How to copy existing database from one app to another

Second Approach copy the contents of two database

Step-1 First Attach two databases

ATTACH DATABASE filename AS database-name;

The DATABASE keyword is optional, but I like the clarity of it. filename should be the path to the database file you wish to attach, and the database-name is a unique name.

Step-2 Run Insert Into commands for the tables you want to transfer.

INSERT INTO X.TABLE(Id, Value) SELECT * FROM Y.TABLE;

Upvotes: 1

Related Questions