sqlite3 常用命令
1.打开my.db 不存在则创建
sqlite3 my.db
创建/打开当前数据库创建的特定数据库
.open xxx.db
2.帮助
.help
3.退出
.quit
4.显示打开的数据库
.database
5.显示数据库中的表
.tables
6.显示tablename的结构
.schema tablename
7.保存
.save
8.其他
.backup ?DB? FILE 备份数据库Backup DB (default "main") to FILE
.changes on|off 显示行号Show number of rows changed by SQL
.clone NEWDB 从指定数据库复制数据到NEWDB数据库中Clone data into NEWDB from the existing database
.databases 列表数据库List names and files of attached databases
.dbinfo ?DB? 显示数据库的状态信息Show status information about the database
.echo on|off 显示执行的SQL语句Turn command echo on or off
.excel Display the output of next command in spreadsheet
.exit ?CODE? 退出控制台带返回值 Exit this program with return-code CODE
.headers on|off 显示表的每列的标题 Turn display of headers on or off
.help ?-all? ?PATTERN? 查看控制台命令帮助Show help text for PATTERN
.import FILE TABLE 导入数据库文件Import data from FILE into TABLE
.imposter INDEX TABLE 创建表或表索引号Create imposter table TABLE on index INDEX
.indexes ?TABLE? 依据表索引号显示表名Show names of indexes
.log FILE|off 日志文件开关Turn logging on or off. FILE can be stderr/stdout
.mode MODE ?TABLE? Set output mode
.open ?OPTIONS? ?FILE? 创建打开,或关闭当前数据库打开新的数据库Close existing database and reopen FILE
.output ?FILE? Send output to FILE or stdout if FILE is omitted
.save FILE 保存文件Write in-memory database into FILE
常用语句
创建表
create table usr (name text,passwd text);
创建有主键的表
create table usr (name text primary key,passwd text )
向表中插入数据
insert into usr values(“sunny”,“ps999”);
查询表中所有数据
select *from usr;
查询表中特定数据
select *from usr where name = “sunshine” and passwd = “ps888”;
按规则查找
delete from usr where name = “sunbow”;
更新表
updata usr set passwd = “abc123” where name= “sunbow”;
删除表
drop table usr;
相关头文件
#include <sqlite3.h>
相关函数
打开/创建数据库
sqlite3_open();
执行sql语句
sqlite3_exec();
查询
sqlite3_get_table();
关闭
sqlite3_close();
编译时:指定连接库名 -lsqlite3
例子
QT-Day6-6