安装sqlite
apt-get install sqlite3
进入和退出
sqlite3 //进入sqlite3,内容保存至内存,退出后内容会丢失
sqlite3 <表名> //保存到文件中,例sqlite3 student
.exit //退出sqlite3,‘.'不能少
创建表
#以学生表为例 create table student(id integer,name text,age integer);
查看表结构
.schema
插入数据
insert into student(id,name,age) values(1,"aa",11);
insert into student(id,name,age) values(1,"aa",11),values(2,"bb",12);//部分sqlite3可能不支持多条插入
查询数据
select * from student;
修改数据
update student set age = 25 where id = 3;
删除数据
delete from student where id = 1;
删除表
drop table student;
sqlite3 C语言API
找不到sqlite3.h时执行 apt-get install libsqlite3-dev 安装
打开或创建数据库
sqlite3 *ppdb; int ret = sqlite3_open("student.db",&ppdb); if(ret != SQLITE3_OK) { printf("sqlite3 open error:%s\n",sqlite3_errmsg(ppdb)); exit(1); }
创建表
char sql[128] = {0}; spirntf(sql,"create table if not exists student(id integer,name text,age integer);");
ret = sqlite3_exec(ppdb,sql,NULL,NULL,NULL);
if(ret != SQLITE_OK)
{
printf("sqlite3_execl err:%s\n",sqlite3_errmsg(ppdb));
exit(1);
}
插入操作
scanf("%d%s%d,$id,name,&age); sprintf(sql,"insert into student values(%d,'%d',%d); ret = sqlite3_exec(ppdb,sql,NULL,NULL);
标签:name,ppdb,C语言,age,api,student,sqlite3,id From: https://www.cnblogs.com/ddrm/p/17663840.html