sqllite3常用命令


--內容摘要:1.利用adb工具進入 shell:adb shell。(在電腦的cmd打開,進入到Android安裝目錄的tools目錄下)2.
ls查看當前目錄,進入data/data/…../databases/。目錄3.打開某個數據庫:SQLite 3
xxx.db。4.查詢等sql語句:select * from xxxtable;。SQLite 3: 一個SQLite數據庫的命令行接口。。。

 

$ adb shell

$ cd /data/data/com.android.providers.media/databases       //進入
media數據庫目錄


$ sqlite3 settings.db                                                       //啟動sqlite3
SQLite version 3.6.22
Enter ".help" for instructions                                            //輸入.help獲取幫助信息
Enter SQL statements terminated with a ";"                       //SQL命令以;作為結束符

sqlite> .tables                                                             //查看當前的table

android_metadata   bookmarks          system          
bluetooth_devices  secure  


sqlite> .headers ON                                                                    //顯示表頭信息


sqlite>  select * from secure;                                        //查看secure表中的值,命令以;結束

sqlite> select * from audio_genres;
_id|name                                                                    //只有
.headers ON打開后才有表頭顯示
1|Unknown
2|Other
3|Rock
4|Soul And R&B
5|pop
6|Soundtrack
7|Goa
8|Pop
9|華語流行音樂【Chinese Pop Music】
10|POP
11|148
12|Blues
13|genre
14|Asian
15|www.ting30.com
16|General Rock
17|Folk
18|General Soundtrack


sqlite>  INSERT INTO secure (name, value) VALUES (‘device_provisioned’, 1);   //向secure 表中插入device_provisioned,其值設置為1

sqlite>  .exit                                                                                        //退出


附錄: SQL常用命令


(1) 數據記錄篩選:

sql="select * from 數據表 where 字段名=字段值 order by 字段名 [desc]"

sql="select * from 數據表 where 字段名 like '%字段值%' order by 字段名 [desc]"

sql="select top 10 * from 數據表 where 字段名 order by 字段名 [desc]"

sql="select * from 數據表 where 字段名 in ('值1','值2','值3')"

sql="select * from 數據表 where 字段名 between 值1 and 值2"

(2) 更新數據記錄:

sql="update 數據表 set 字段名=字段值 where 條件表達式"

sql="update 數據表 set 字段1=值1,字段2=值2 …… 字段n=值n where 條件表達式"

(3) 刪除數據記錄:

sql="delete from 數據表 where 條件表達式"

sql="delete from 數據表" (將數據表所有記錄刪除)

(4) 添加數據記錄:

sql="insert into 數據表 (字段1,字段2,字段3 …) valuess (值1,值2,值3 …)"

sql="insert into 目標數據表 select * from 源數據表" (把源數據表的記錄添加到目標數據表)

(5) 數據記錄統計函數:

AVG(字段名) 得出一個表格欄平均值
COUNT(*|字段名) 對數據行數的統計或對某一欄有值的數據行數統計
MAX(字段名) 取得一個表格欄最大的值
MIN(字段名) 取得一個表格欄最小的值
SUM(字段名) 把數據欄的值相加

引用以上函數的方法:

sql="select sum(字段名) as 別名 from 數據表 where 條件表達式"
set rs=conn.excute(sql)

用 rs("別名") 獲取統的計值,其它函數運用同上。

(6) 數據表的建立和刪除:

CREATE TABLE 數據表名稱(字段1 類型1(長度),字段2 類型2(長度) …… )

例:CREATE TABLE tab01(name varchar(50),datetime default now())

DROP TABLE 數據表名稱 (永久性刪除一個數據表)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM