SQLite基本操作

2021-06-27 05:29:20 字數 1085 閱讀 7155

sqlite的基本操作:建庫、建表、插入資料、修改資料、刪除資料、刪除表、刪除庫。

1、建庫

在命令列下輸入》sqlite3 test.db                              //注意當前是什麼使用者如果是root使用者則該庫建立在/home目錄下,其他使用者庫建立在使用者的根目錄下

sqlite>.database   顯示建立的資料庫

2、建表

>sqlite3 test.db

sqlite>create table infor(name varchar(10),age int);

3、插入資料

sqlite>insert into infor values('liu',23);

sqlite>insert into infor values('zhang',22);

sqlite>insert into infor values('li',24);

檢視記錄

sqlite>select * from infor 

liu | 23

zhang | 22

li | 24

4、刪除資料

sqlite>delete from infor where name like 'li';

sqlite>select * from infro;

liu | 23

zhang | 22

5、更新資料

sqlite> update infor set age=20 where name = 'zhang';

sqlite>select * from infor;

liu | 23

zhang | 20

6、檢視表和庫的資訊

sqlite>.tables

infor

sqlite>.database

0 main /home/sqlite/test.db

1temp

7、刪除表

sqlite>drop table infor;

sqlite>.tables

sqlite>

8、刪除庫

>rm test.db

sqlite基本操作

sqlite 是一種輕型資料庫系統,並以嵌入式為設計目標,占用資源低,因此作為手機作業系統優秀的資料庫系統選擇平台。sqlite 的使用涉及兩個重要的類,乙個是sqliteopenhelper和sqlitedatabase,sqliteopenhelper 是sqlite 的資料庫輔助類,而 sql...

SQLite 基本操作

建立資料庫 命令 sqlite3 name.db 此命令會在當前目錄建立乙個名為name.db的空資料庫。該檔案將被 sqlite 引擎用作資料庫。在成功建立資料庫檔案之後,將提供乙個sqlite 提示符。如下 sqlite version 3.31.1 2020 01 27 19 55 54 en...

Sqlite 安裝 基本操作

最近搞sqlite 資料庫,整理一下,備忘。1.安裝 sudo yum install sqlite devel 2.基本操作 建立資料庫 sqlites test.db 建立資料表 create table testtable id int primery key,name varchar 20 ...