學習sqlite3(二)

一、基本數據庫操作

1、啓動命令行,通過如下命令打開Shell模式的CLP:

splite3 test.db

2、shell中創建表

sqlite> create table test(id interger primary key,value text);

3、向表中插入幾行

sqlite> insert into test (id,value) values(1,'djsh')

4、返回插入內容

sqlite> .mode column
sqlite> .headers on
sqlite> select* from test

5、顯示內容如圖所示:

id       value
------   -------
1         ennie
2         meenie
3         miny
4         mo

6、使用SQL函數last_insert_rowid()獲得最後插入的自動增量值

sqlite> select last_insert_rowid();

7、返回表

sqlite> .indices test

8、爲表添加索引和視圖

sqlite> create index test_idx on test (value);
sqlite> create view schema as select * from sqlite_master;

9、顯示錶的索引

sqlite> .indices test

10、顯示錶的視圖

sqlite> .schema test
sqlite> .schema

11、查詢當前數據庫的sqlite_master表

sqlite> select tupe,name,tbl_name,sql from sqlite_master order by type

12、打開數據庫

sqlite3 foods.db

13、更改數據表

alter table contacts add column email text not null default ''collate nocase;

14、查看錶定義

sqlite> .schema contacts

二、數據庫基本概念

1、test.db對象的完整清單包括:一個表、一個索引和一個視圖
2、SQL 關鍵字 select、update、insert、create、drop、begin
3、SQL組成部分:
1)數據庫定義語言(DDL)—用來創建和銷燬數據庫對象的部分
2)數據庫操作語言(DML)—咋數據庫對象上執行操作的功能部分
3)Sqlite 中有5中本地類型:integer/real/text/blobl/null

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章