sqlite3 數(shù)據(jù)庫簡介
SQLite 數(shù)據(jù)庫,是一個非常輕量級自包含(lightweight and self-contained)的DBMS,它可移植性好,很容易使用,很小,高效而且可靠。
SQLite嵌入到使用它的應(yīng)用程序中,它們共用相同的進(jìn)程空間,而不是單獨(dú)的一個進(jìn)程。從外部看,它并不像一個RDBMS,但在進(jìn)程內(nèi)部,它卻是完整的,自包含的數(shù)據(jù)庫引擎。
嵌入式數(shù)據(jù)庫的一大好處就是在你的程序內(nèi)部不需要網(wǎng)絡(luò)配置,也不需要管理。因?yàn)榭蛻舳撕头?wù)器在同一進(jìn)程空間運(yùn)行。
SQLite 的數(shù)據(jù)庫權(quán)限只依賴于文件系統(tǒng),沒有用戶帳戶的概念。SQLite 有數(shù)據(jù)庫級鎖定,沒有網(wǎng)絡(luò)服務(wù)器。它需要占用內(nèi)存,但其它開銷很小,適合用于嵌入式設(shè)備,你需要做的僅僅是把它正確的編譯到你的程序。sqlite常用查詢語句
SQLite創(chuàng)建數(shù)據(jù)庫
SQLite使用起來非常方便,僅僅需要敲入帶有SQLite數(shù)據(jù)庫名字的"sqlite3"命令即可。如果文件不存在,則創(chuàng)建一個新的(數(shù)據(jù)庫)文件。然后sqlite3程序?qū)⑻崾灸爿斎隨QL。敲入SQL語句以分號“;”結(jié)束,敲回車鍵之后,SQL語句就會執(zhí)行。例如,創(chuàng)建一個包含一個數(shù)據(jù)庫為“user.db”表“cars”的SQLite數(shù)據(jù)庫。創(chuàng)建命令:
創(chuàng)建數(shù)據(jù)庫user.db
sqlite3 user.db創(chuàng)建表cars
create table carsl(name varchar(10), years smallint, price float);
查詢表
.table
插入數(shù)據(jù)
insert into cars values('audi', 1994, 530000.5);insert into cars values('volvo', 2001, 303478.5);
顯示頭
.header on
修改顯示模式
.mode column
查詢數(shù)據(jù)
select * from cars; //查詢cars表 中所有數(shù)據(jù)
sqlite> select * from tbl1 where one='xxx';
刪除全部語句
sqlite> delete from cars;
更新語句
sqlite>update cars set name='kaka' where name="mini";
刪除語句
sqlite> delete from cars where name="kaka";
sqlite>delete from cars; //刪除 cars表 中所有數(shù)據(jù)
條件語句的應(yīng)用 "and" "or" "and or"
sqlite> delete from cars where name="volvo"
or
name="audi";
sqlite> delete from cars where name="volvo"
and
price=324200;
sqlite> delete from cars where (name="volvo"
or
name="audi") and price=324203;
顯示結(jié)果:
其操作和普通的關(guān)系數(shù)據(jù)庫沒有太大的差異,可以很方便的對數(shù)據(jù)進(jìn)行增、刪、改、查。SQLite可以使用8種方式顯示查詢結(jié)果,大大方便了程序?qū)?shù)據(jù)的處理,sqlite3程序可以以八種不同的格式顯示一個查詢的結(jié)果:
.mode MODE ?TABLE? Set output mode where MODE is one of:
csv Comma-separated values
column Left-aligned columns. (See .width)
html HTML <table> code
insert SQL insert statements for TABLE
line One value per line
list Values delimited by .separator string
tabs Tab-separated values
tcl TCL list elements
使用方法: .mode column (輸出格式切換到行模式,如上圖)
SQLite3 導(dǎo)入導(dǎo)出數(shù)據(jù)庫
導(dǎo)出數(shù)據(jù)庫
sqlite> .databases (顯示數(shù)據(jù)庫)
sqlite> .backup main user.sql (備份數(shù)據(jù)庫main, 即完成數(shù)據(jù)庫的復(fù)制)sqlite> .backup user2.sql (備份默認(rèn)數(shù)據(jù)庫main)
同時sqlite具有導(dǎo)入/出表,文件,數(shù)據(jù)庫等功能(具體詳見 ./help)
參考來源: http://www.cnblogs.com/wdpp/archive/2011/11/30/2386714.html
推薦參考: sqlite官網(wǎng)
http://blog.csdn.net/xing_hao/article/details/6660589
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯(lián)系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長非常感激您!手機(jī)微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
