網(wǎng)站logo做黑頁百度首頁精簡版
頭文件: #include <sqlite3.h> 編譯時候要加上-lsqlite3 ? ?gcc a.c -lsqlite3
1)sqlite3_open 打開一個數(shù)據(jù)庫,如果數(shù)據(jù)庫不存在,則創(chuàng)建一個數(shù)據(jù)庫
2)sqlite3_close 關(guān)閉數(shù)據(jù)庫,斷開句柄所擁有的資源
3)sqlite3_errmsg 通過出錯的句柄返回錯誤信息
4)sqlite3_errcode 通過錯誤句柄返回錯誤碼
5)sqlite3_exec 調(diào)用該函數(shù),執(zhí)行sql語句
6)回調(diào)函數(shù)callback 處理sqlite3_exec執(zhí)行sql語句后的結(jié)果集,每有一條記錄,就會執(zhí)行一次callback函數(shù)
7)sqlite3_get_table 通過執(zhí)行sql語句,得到結(jié)果集中的內(nèi)容
8)sqltie3_free_table 釋放表的空間
1)創(chuàng)建表
create table 表名 (字段名 數(shù)據(jù)類型, 字段名 數(shù)據(jù)類型);
create table if not exists 表名 (字段名 數(shù)據(jù)類型, 字段名 數(shù)據(jù)類型);
2)刪除表
drop table 表名;
3)插入
1) 全字段插入 insert into 表名 values (數(shù)據(jù)1, 數(shù)據(jù)2, 數(shù)據(jù)3);
2) 部分字段插入 insert into 表名 (字段名1, 字段名2) values (數(shù)據(jù)1, 數(shù)據(jù)2);
4)查看
1) 查看所有記錄 select * from 表名;
2) 查看某幾行 select * from 表名 where 限制條件;
邏輯與 and 邏輯或 or
3)查看某幾列
1、 select 字段1, 字段2 from 表名;
?2、select 字段1, 字段2 from 表名 where 限制條件;
5)修改
update 表名 set 字段=數(shù)值 where 限制條件;
6)刪除
delete from 表名 where 限制條件; ?
7)主鍵
primary key 主鍵;
?create table 表名(字段名 數(shù)據(jù)類型 primary key, 字段名 數(shù)據(jù)類型); primary key主鍵:唯一標(biāo)識表格中的每一條記錄;
8)拷貝
從a中拷貝所有數(shù)據(jù)到b中: create table b as select * from a;
從a中拷貝指定字段到b中: create table b as select 字段,字段,字段 from a;
9)增加列
alter table 表名 add column 字段名 數(shù)據(jù)類型;
10)修改表名
alter table 舊表名 rename to 新表名;
11)修改字段名(列名)
不支持直接修改列名
1.將表重新命名(a改成b)
alter table stuinfo rename to stu;
2.新建修改名字后的表(新建一個a)
?create table stuinfo (name char, age1 int, sex char, score int);
3.從舊表b中取出數(shù)據(jù),插入到新表a中; insert into stuinfo select * from stu;
12)刪除列
不支持直接刪除列;
1.創(chuàng)建一個新表b,并復(fù)制舊表a需要保留的字段信息;
?create table stu as select name, age1, sex from stuinfo;
2.刪除舊表a;
drop table stuinfo;
3.修改新表b的名字a;
alter table stu rename to stuinfo;
————————————————
? ? ? ? ? ? ? ? ? ? ? ? ? ? 版權(quán)聲明:本文為博主原創(chuàng)文章,遵循 CC 4.0 BY-SA 版權(quán)協(xié)議,轉(zhuǎn)載請附上原文出處鏈接和本聲明。
? ? ? ? ? ? ? ? ? ? ? ??
原文鏈接:https://blog.csdn.net/2301_79965609/article/details/136079457