901 sqlite資料庫的匯出與匯入

2021-10-09 21:44:04 字數 1637 閱讀 2980

sqlite 僅僅支援 alter table 語句的一部分功能,我們可以用 alter table 語句來更改乙個表的名字,也可向表中增加乙個字段(列),但是我們不能刪除乙個已經存在的字段,或者更改乙個已經存在的字段的名稱、資料型別、限定符等等。

改變表名 - alter table 舊表名 rename to 新錶名

增加一列 - alter table 表名 add column 列名 資料型別

select name from sqlite_master where type='table' order by name;
1,匯出資料庫某個表:

# 先執行

.output table_name.sql

# 在執行

.dump table_name

如果是匯出全部表:

直接 .dump

2,匯入資料表:

.read table_name.sql
1,匯出表:

cmd = "sqlite3 db.sqlite3 '.dump table_name' > table_name.sql"

os.system(cmd)

2,匯入表:

cmd = "sqlite3  db.sqlite3 '.read table_name.sql' "

os.system(cmd)

執行「sqlite3.exe」,我們可能用到下面幾個命令:

sqlite> .help

.dump ?table? ... dump the database in an sql text format

if table specified, only dump tables matching

like pattern table.

.exit exit this program

.help show this message

.open ?--new? ?file? close existing database and reopen file

the --new starts with an empty file

.output ?filename? send output to filename or stdout

.quit exit this program

.read filename execute sql in filename

.tables ?table? list names of tables

if table specified, only list tables matching

like pattern table.

sqlite>

sqlite3  -csv -header vz3.db  "select * from t_city_domestic_all_new" > city.csv
參考:

匯出SQLite資料庫檔案並檢視

第一步 匯出資料庫檔案 輸入adb shell回車 輸入cd data data example databases回車,進入資料庫資料夾 example這裡填你的應用包名 輸入ls檢視資料庫 demo.db就是本次操作物件 輸入exit退出adb shell 輸入cd c users dh des...

Sqlite資料庫的鎖

在sqlite中,鎖和事務是緊密聯絡的。為了有效地使用事務,需要了解一些關於如何加鎖的知識。sqlite採用粗放型的鎖。當乙個連線要寫資料庫,所有其它的連線被鎖住,直到寫連線結束了它的事務。sqlite有乙個加鎖表,來幫助不同的寫資料庫都能夠在最後一刻再加鎖,以保證最大的併發性。sqlite使用鎖逐...

資料庫的管理SQLite

sqliteopenhelper 通過繼承這個類,開發者可以很容易的設計和運算元據庫,注意封裝會使android的效能降低,在繼承sqliteopenhelper時候必須實現oncreate onupgrade 函式 public class dbhelper extends sqliteopenh...