Requirements:
There are two different SQLite databases A and B. You need to copy the tables in database B to database.
Prerequisites:
Install ADB.
Principle:
First, you will use sqlite3 to open a database, and then use the attach command to import another database. Then, you can access the tables in the introduced database with a special name.
Case:
Dictionary has a t_words table. I need to copy it to sentences. DB.
Procedure:
1. First enable ADB on the terminal. The command is ADB shell and the corresponding file is located.
2. sqlite3 dictionary: Open the dictionary database. (Remove the dictionary extension in advance, otherwise there will be a problem later ).
. Schema command to view the table creation.
# Sqlite3 dictionarysqlite version 3.7.4enter ". help "for instructionsenter SQL statements terminated with a"; "SQLite>. schemacreate table android_metadata (locale text); Create Table [t_words] ([English] varchar (30) not null on conflict fail, [Chinese] varchar (100) not null on conflict fail, constraint [english_primary] primary key ([English]); SQLite>
Record the command for creating t_words tables, which will be used later.
3. Run the. Q command to exit the database, and sqlite3 sentences. dB to enter the sentences database. Use the command just recorded to create a t_words table identical to the dictionary. schema to check whether the table is successfully created;
4. Execute attach database dictionary as DIC. Then you can use DIC to reference the dictionary database;
5. Execute insert into t_words select * from DIC. t_words, wait for 1 S, and the copy is complete.
Note:
1) create a table first and then insert it instead of directly using
Create Table T2 as select *From db1.t1;
Because the directly created table is different from the original table!
2) The command executed in SQLite ends with ";". Remember to repeat it.
Reference: http://www.cnblogs.com/nmj1986/archive/2012/09/17/2688827.html