自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

SQLlite數(shù)據(jù)庫中的附加和分離

數(shù)據(jù)庫 其他數(shù)據(jù)庫
在SQLlite數(shù)據(jù)庫中往往一個數(shù)據(jù)文件就是一個schema,但是在平時的業(yè)務(wù)或者是一些條件中可能是不同的內(nèi)容存放在不同的schema中,即不同的數(shù)據(jù)文件,有的場景下需要數(shù)據(jù)關(guān)聯(lián)時就可以使用SQLlite的數(shù)據(jù)附加來建立一個臨時的鏈接。

[[215572]]

在SQLlite數(shù)據(jù)庫中往往一個數(shù)據(jù)文件就是一個schema,但是在平時的業(yè)務(wù)或者是一些條件中可能是不同的內(nèi)容存放在不同的schema中,即不同的數(shù)據(jù)文件,有的場景下需要數(shù)據(jù)關(guān)聯(lián)時就可以使用SQLlite的數(shù)據(jù)附加來建立一個臨時的鏈接。如下,在使用my_test的schema時需要關(guān)聯(lián)查詢一個為my_test2的schema就可以使用附加:

  1. [root@localhost data]# sqlite3 my_test.db #在SQLlite數(shù)據(jù)庫中缺省database名為main 
  2. SQLite version 3.6.20 
  3. Enter ".help" for instructions 
  4. Enter SQL statements terminated with a ";" 
  5. sqlite> .database 
  6. seq  name             file                                                      
  7. ---  ---------------  ---------------------------------------------------------- 
  8. 0    main             /data/my_test.db 
  9. sqlite> ATTACH DATABASE '/data/my_test2.db' As 'my_test2'; #在當(dāng)前schema下附加上/data/my_test2.db中的數(shù)據(jù),并且起一個別名為my_test2,當(dāng)然也可以起其他的名字 
  10. sqlite> .databases 
  11. seq  name             file                                                      
  12. ---  ---------------  ---------------------------------------------------------- 
  13. 0    main             /data/my_test.db                                          
  14. 2    my_test2         /data/my_test2.db 
  15. sqlite> CREATE TABLE my_test2.test_attach ( 
  16.    ...>   a int(10), 
  17.    ...>   b int(10) 
  18.    ...> ); 
  19. sqlite> SELECT * FROM my_test2.sqlite_master WHERE type = 'table' AND tbl_name = 'test_attach';  #直接在當(dāng)前schema下使用/data/my_test2.db中的數(shù)據(jù),并且查看 
  20. table|test_attach|test_attach|4|CREATE TABLE test_attach ( 
  21.   a int(10), 
  22.   b int(10) 
  23. sqlite> .exit 
  24. [root@localhost data]# sqlite3 /data/my_test2.db #切換成my_test2.db的schema查看驗證下 
  25. SQLite version 3.6.20 
  26. Enter ".help" for instructions 
  27. Enter SQL statements terminated with a ";" 
  28. sqlite> SELECT sql FROM sqlite_master WHERE type = 'table' AND tbl_name = 'test_attach'
  29. CREATE TABLE test_attach ( 
  30.   a int(10), 
  31.   b int(10) 

如此就是在SQLlite數(shù)據(jù)庫中的附加數(shù)據(jù)庫,它其實是一個鏈接,用于在不同的數(shù)據(jù)schma數(shù)據(jù)文件下使用其他的schma數(shù)據(jù)文件,在這里需要注意的是目前在SQLlite數(shù)據(jù)庫中附加是臨時的,在當(dāng)前session中創(chuàng)建一個鏈接,如果在退出這個session后附加就自動分離:

  1. [root@localhost data]# sqlite3 /data/my_test.db  
  2. SQLite version 3.6.20 
  3. Enter ".help" for instructions 
  4. Enter SQL statements terminated with a ";" 
  5. sqlite> .database 
  6. seq  name             file                                                      
  7. ---  ---------------  ---------------------------------------------------------- 
  8. 0    main             /data/my_test.db 
  9. 當(dāng)然有如果有附件數(shù)據(jù)庫那一定有分離,分離就比較簡單: 
  10.  
  11. sqlite> .databases 
  12. seq  name             file                                                      
  13. ---  ---------------  ---------------------------------------------------------- 
  14. 0    main             /data/my_test.db                                          
  15. 2    my_test2         /data/my_test2.db 
  16. sqlite> DETACH DATABASE "my_test2"
  17. sqlite> .databases                  
  18. seq  name             file                                                      
  19. ---  ---------------  ---------------------------------------------------------- 
  20. 0    main             /data/my_test.db 

這樣就成功的主動分離附加在當(dāng)前schma下的其他數(shù)據(jù)文件,在這里要特別注意的是如果分離的數(shù)據(jù)庫是在內(nèi)存或臨時空間內(nèi),分離后會銷毀其分離的數(shù)據(jù)。

責(zé)任編輯:武曉燕 來源: Linux社區(qū)
相關(guān)推薦

2010-07-06 14:40:15

解決SQL Serve

2022-12-05 07:51:24

數(shù)據(jù)庫分庫分表讀寫分離

2010-07-14 14:36:24

SQL Server附

2018-02-24 19:37:33

Java8數(shù)據(jù)庫中間件

2022-12-15 09:44:29

數(shù)據(jù)庫利器

2024-09-20 07:38:00

數(shù)據(jù)庫性能策略

2010-07-22 10:09:21

2010-03-26 09:46:32

SQL Server

2017-03-14 13:12:19

2011-07-15 15:55:50

SQL Server日附加數(shù)據(jù)庫

2011-05-30 14:30:08

函數(shù)存儲過程

2009-05-08 09:56:37

MaxDBMySQL數(shù)據(jù)庫管理

2011-05-13 13:38:49

數(shù)據(jù)庫對象

2018-10-16 16:45:05

數(shù)據(jù)庫讀寫分離

2011-10-11 17:07:12

數(shù)據(jù)庫Internet文件數(shù)據(jù)庫

2010-09-01 16:55:55

SQL刪除連接

2010-10-22 15:59:59

sqlserver刪除

2020-03-24 14:16:18

ProxySQLMySQL數(shù)據(jù)庫

2018-01-26 13:28:48

數(shù)據(jù)庫數(shù)據(jù)重復(fù)數(shù)據(jù)庫清理

2011-07-04 09:12:53

數(shù)據(jù)庫采購
點贊
收藏

51CTO技術(shù)棧公眾號