I. Attach database:
The attach database statement adds another database file to the current connection. If the file name is ": Memory:", we can regard it as a memory database, and the memory database cannot be persisted to the disk file. If you operate a table in the attached database, you must add the database name before the table name, for example, dbname. table_name. It should be noted that if a transaction contains multiple attached database operations, the transaction is still atomic. See the following example:
SQLite> Create Table testtable (first_col integer );
SQLite> insert into testtable values (1 );
SQLite>. Backup'D:/mydb. db' -- Back up the master database in the current connection to the specified file.
SQLite>. Exit
-- Log on to the SQLite command line tool again:
SQLite> Create Table testtable (first_col integer );
SQLite> insert into testtable values (2 );
SQLite> insert into testtable values (1 );
SQLite>Attach Database'D:/mydb. db'AsMydb;
SQLite>. Header on-- The field name is output as the title in the query result.
SQLite>. Mode Column-- Display each column separately.
SQLite> select t1.first _ Col from testtable T1,Mydb. testtableT2 where T. first_col = t2.first _ Col;
First_col
----------
1
Ii. Detach database:
Detaching: Specifies the database in the current connection. Note that the main and temp databases cannot be detached. See the following example:
-- This example carries the result of the preceding example, that is, the mydb database has been attach to the current connection.
SQLite>Detach DatabaseMydb;
SQLite> select t1.first _ Col from testtable T1, mydb. testtable T2 where T. first_col = t2.first _ Col;
Error: no such table: mydb. testtable
Iii. transactions:
In SQLite, if no specified transaction is displayed for the current SQL command (except select), SQLite automatically adds an implicit transaction for this operation, to ensure the atomicity and consistency of the operation. Of course, SQLite also supports transactions displayed. Its syntax is basically the same as that of most relational databases. See the following example:
SQLite> Begin transaction ;
SQLite> insert into testtable values (1 );
SQLite> insert into testtable values (2 );
SQLite> Commit transaction ; -- The transaction is committed, and the data in the data table has also changed.
SQLite> select count (*) from testtable;
Count (*)
----------
2
SQLite> Begin transaction ;
SQLite> insert into testtable values (1 );
SQLite> Rollback transaction ; -- Indicates that the transaction is rolled back, and the data in the data table has not changed.
SQLite> select count (*) from testtable;
Count (*)
----------
2