Append and detach in the Sqllite database

Source: Internet
Author: User
Tags sqlite

In the Sqllite database is often a data file is a schema, but in peacetime business or some conditions may be different content stored in different schemas, that is, different data files, There are scenarios where data correlation is required to create a temporary link using the Sqllite data attachment. as follows, when using the schema of my_test, you need to correlate the query with a schema for the my_test2 to use the Append:

[[email protected] data]# sqlite3 my_test.db  #在SQLlite数据库中缺省database名为mainSQLite  version 3.6.20Enter  ". Help"  for instructionsEnter SQL statements  terminated with a  ";" sqlite> .databaseseq  name              file                                                         ---  ---------------  -------------------------------------------------- --------0    main              /data/my_test.dbsqlite> ATTACH DATABASE  '/data/my_test2.db '  As  ' my_tEst2 ';  #在当前schema下附加上 the data in/data/my_test2.db, and an alias is My_test2, and of course other names are available SQLITE> .DATABASESSEQ   name             file                                                         ---   ---------------  ----------------------------------------------------------0     main             /data/my_test.db                                            &nbsP;2    my_test2         /data/my_ test2.dbsqlite> create table my_test2.test_attach  (   ...>    a int (Ten),    ...>   b int    ...>  );sqlite> select * from my_test2.sqlite_master where type =  ' Table '  AND tbl_name =  ' Test_attach ';   #直接在当前schema下使用/data/my_ Test2.db in the data, and view the table|test_attach|test_attach|4| create table test_attach  (  a int),   b int (Ten)) sqlite>  .exit[[email protected] data]# sqlite3 /data/my_test2.db  #切换成my_ Test2.db Schema View validation under sqlite version 3.6.20enter  ". Help"  for instructionsenter sql  statements terminated with a  ";" Sqlite> select sql from sqlite_master where type =  ' table '  AND tbl_name =  ' Test_attach '; create table test_attach  (  a int),   b int (10))

is the additional database in the Sqllite database, which is actually a link for using other Schma data files under different data Schma data files. It is important to note here that the current append in the Sqllite database is temporary, creating a link in the current session and automatically detaching if appended after exiting the session:

[Email protected] data]# sqlite3/data/my_test.db SQLite version 3.6.20Enter ". Help" for Instructionsenter SQL statements Terminated with a ";"  sqlite>. databaseseq name File------------------ ----------------------------------------------------------0 main/data/my_test.db

Of course, if there is an attachment database that there must be separation, separation is relatively simple:

sqlite> .databasesseq  name              file                                                         ---  ---------------  -------------------------------------------- --------------0    main              /data/my_test.db                                            2    my_test2          /data/my_test2.dbsqlite> detach database  "My_test2"; sqlite> .databases                  seq   name             file                                                         ---   ---------------  ----------------------------------------------------------0     main             /data/my_test.db

In this way, the successful active separation of additional data files attached to the current Schma, it is particularly important to note that if the detached database is in memory or in a temporary space, the detached data will be destroyed after separation

Append and detach in the Sqllite database

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.