69pao国产精品视频-久久精品一区二区二三区-精品国产精品亚洲一本大道-99国产综合一区久久

SQLite 分離數(shù)據(jù)庫

sqlite 分離數(shù)據(jù)庫

sqlite 的 detach database 語句是用來把命名數(shù)據(jù)庫從一個數(shù)據(jù)庫連接分離和游離出來,連接是之前使用 attach 語句附加的。如果同一個數(shù)據(jù)庫文件已經(jīng)被附加上多個別名,detach 命令將只斷開給定名稱的連接,而其余的仍然有效。您無法分離 maintemp 數(shù)據(jù)庫。

如果數(shù)據(jù)庫是在內(nèi)存中或者是臨時數(shù)據(jù)庫,則該數(shù)據(jù)庫將被摧毀,且內(nèi)容將會丟失。

 

1. 語法

sqlite 的 detach database 'alias-name' 語句的基本語法如下:

detach database 'alias-name';

在這里,'alias-name' 與您之前使用 attach 語句附加數(shù)據(jù)庫時所用到的別名相同。

 

2. 范例

假設(shè)在前面的章節(jié)中您已經(jīng)創(chuàng)建了一個數(shù)據(jù)庫,并給它附加了 'test' 和 'currentdb',使用 .database 命令,我們可以看到:

sqlite>.databases
seq  name             file
---  ---------------  ----------------------
0    main             /home/sqlite/testdb.db
2    test             /home/sqlite/testdb.db
3    currentdb        /home/sqlite/testdb.db

現(xiàn)在,讓我們嘗試把 'currentdb' 從 testdb.db 中分離出來,如下所示:

sqlite> detach database 'currentdb';

現(xiàn)在,如果檢查當(dāng)前附加的數(shù)據(jù)庫,您會發(fā)現(xiàn),testdb.db 仍與 'test' 和 'main' 保持連接。

sqlite>.databases
seq  name             file
---  ---------------  ----------------------
0    main             /home/sqlite/testdb.db
2    test             /home/sqlite/testdb.db

下一節(jié):sqlite 創(chuàng)建表

sqlite教程

相關(guān)文章