av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

您的位置:首頁技術(shù)文章
文章詳情頁

SQLite數(shù)據(jù)庫安裝及基本操作指南

瀏覽:293日期:2023-04-05 14:56:06

1. 介紹

SQLite 是一個開源的嵌入式關(guān)系數(shù)據(jù)庫,實現(xiàn)自包容、零配置、支持事務(wù)的SQL數(shù)據(jù)庫引擎。 其特點是高度便攜、使用方便、結(jié)構(gòu)緊湊、高效、可靠。 與其他數(shù)據(jù)庫管理系統(tǒng)不同,SQLite 的安裝和運行非常簡單,在大多數(shù)情況下 - 只要確保SQLite的二進(jìn)制文件存在即可開始創(chuàng)建、連接和使用數(shù)據(jù)庫。如果您正在尋找一個嵌入式數(shù)據(jù)庫項目或解決方案,SQLite是絕對值得考慮。

2. 安裝

SQLite on Windows

1)進(jìn)入 SQL 下載頁面:http://www.sqlite.org/download.html

2)下載 Windows 下的預(yù)編譯二進(jìn)制文件包:

sqlite-shell-win32-x86-<build#>.zip
sqlite-dll-win32-x86-<build#>.zip
注意: <build#> 是 sqlite 的編譯版本號

將 zip 文件解壓到你的磁盤,并將解壓后的目錄添加到系統(tǒng)的 PATH 變量中,以方便在命令行中執(zhí)行 sqlite 命令。

可選: 如果你計劃發(fā)布基于 sqlite 數(shù)據(jù)庫的應(yīng)用程序,你還需要下載源碼以便編譯和利用其 API

sqlite-amalgamation-<build#>.zip

SQLite on Linux

在 多個 Linux 發(fā)行版提供了方便的命令來獲取 SQLite:

/* For Debian or Ubuntu /* 
$ sudo apt-get install sqlite3 sqlite3-dev 
 
/* For RedHat, CentOS, or Fedora/* 
$ yum install SQLite3 sqlite3-dev 
SQLite on Mac OS X

如果你正在使用 Mac OS 雪豹或者更新版本的系統(tǒng),那么系統(tǒng)上已經(jīng)裝有 SQLite 了。

3. 創(chuàng)建首個 SQLite 數(shù)據(jù)庫

現(xiàn)在你已經(jīng)安裝了 SQLite 數(shù)據(jù)庫,接下來我們創(chuàng)建首個數(shù)據(jù)庫。在命令行窗口中輸入如下命令來創(chuàng)建一個名為 test.db 的數(shù)據(jù)庫。

sqlite3 test.db
創(chuàng)建表:

sqlite> create table mytable(id integer primary key, value text); 
2 columns were created. 

該表包含一個名為 id 的主鍵字段和一個名為 value 的文本字段。

注意: 最少必須為新建的數(shù)據(jù)庫創(chuàng)建一個表或者視圖,這么才能將數(shù)據(jù)庫保存到磁盤中,否則數(shù)據(jù)庫不會被創(chuàng)建。

接下來往表里中寫入一些數(shù)據(jù):

sqlite> insert into mytable(id, value) values(1, "Micheal"); 
sqlite> insert into mytable(id, value) values(2, "Jenny"); 
sqlite> insert into mytable(value) values("Francis"); 
sqlite> insert into mytable(value) values("Kerk"); 

查詢數(shù)據(jù):

sqlite> select * from test; 
1|Micheal 
2|Jenny 
3|Francis 
4|Kerk 

設(shè)置格式化查詢結(jié)果:

sqlite> .mode column; 
sqlite> .header on; 
sqlite> select * from test; 
id     value 
----------- ------------- 
1      Micheal 
2      Jenny 
3      Francis 
4      Kerk 

.mode column 將設(shè)置為列顯示模式,.header 將顯示列名。

修改表結(jié)構(gòu),增加列:

sqlite> alter table mytable add column email text not null "" collate nocase;; 

創(chuàng)建視圖:

sqlite> create view nameview as select * from mytable; 

創(chuàng)建索引:

sqlite> create index test_idx on mytable(value); 

4. 一些有用的 SQLite 命令

顯示表結(jié)構(gòu):

sqlite> .schema [table] 

獲取所有表和視圖:

sqlite > .tables 

獲取指定表的索引列表:

sqlite > .indices [table ] 

導(dǎo)出數(shù)據(jù)庫到 SQL 文件:

sqlite > .output [filename ] 
sqlite > .dump 
sqlite > .output stdout 

從 SQL 文件導(dǎo)入數(shù)據(jù)庫:

sqlite > .read [filename ] 

格式化輸出數(shù)據(jù)到 CSV 格式:

sqlite >.output [filename.csv ] 
sqlite >.separator , 
sqlite > select * from test; 
sqlite >.output stdout 

從 CSV 文件導(dǎo)入數(shù)據(jù)到表中:

sqlite >create table newtable ( id integer primary key, value text ); 
sqlite >.import [filename.csv ] newtable 

備份數(shù)據(jù)庫:

/* usage: sqlite3 [database] .dump > [filename] */ 
sqlite3 mytable.db .dump > backup.sql 

恢復(fù)數(shù)據(jù)庫:

/* usage: sqlite3 [database ] < [filename ] */ 
sqlite3 mytable.db < backup.sql 
標(biāo)簽: SQLite
相關(guān)文章:
主站蜘蛛池模板: 成人av网站在线观看 | 亚洲一区二区三区视频 | 精品国产免费人成在线观看 | 国产一区二区三区在线 | a级在线免费视频 | 性欧美精品一区二区三区在线播放 | 亚洲精品一二区 | 国产精品美女久久久 | 天天欧美 | 最新免费黄色网址 | 国产精品久久久久久婷婷天堂 | av在线免费观看网址 | 国产综合精品一区二区三区 | 亚洲国产aⅴ成人精品无吗 国产精品永久在线观看 | 国产天天操 | 久久久精 | 一级大黄色片 | 久久不卡 | 亚洲免费网 | 欧美成人a | 日本久久网 | 国产这里只有精品 | 91色啪| 高清成人av| 日韩国产黄色片 | 国产福利在线 | 亚洲成人毛片 | 久久久精品 | 国产精品久久久久久久久图文区 | 亚洲精品久久久久久久久久久 | 久久久久国产精品一区三寸 | 亚洲精品久久久久久久久久久久久 | 九九久久精品视频 | 成人免费网站在线 | 成人国产精品色哟哟 | 亚洲自拍偷拍视频 | 99久久免费观看 | 欧美日韩久久 | 日本天天操 | 亚洲精品中文字幕av | 国产一区二区欧美 |