Android sqlite3命令行操作方法

本文介绍如何使用SQLite命令行工具进行基本操作,包括创建表、显示表结构、插入记录等,并提供了一些常用的命令示例,适合初学者快速上手。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

sqlite3可用命令行实现简便操作,方便手工数据库录入进行测试, 方法如下:

#sqlite3

SQLite version 3.5.9

Enter ".help" for instructions

sqlite>

如使用数据库/data/data/com.android.providers.telephony/databases/telephony.db

则用命令:

#sqlite3 telephony.db

SQLite version 3.5.9

Enter ".help" for instructions

sqlite>.help //帮助命令

.bail ON|OFFStop after hitting an error.Default OFF

.databasesList names and files of attached databases

.dump ?TABLE? ...Dump the database in an SQL text format

.echo ON|OFFTurn command echo on or off

.exitExit this program

.explain ON|OFFTurn output mode suitable for EXPLAIN on or off.

.header(s) ON|OFFTurn display of headers on or off

.helpShow this message

.import FILE TABLEImport data from FILE into TABLE

.indices TABLEShow names of all indices on TABLE

.load FILE ?ENTRY?Load an extension library

.mode MODE ?TABLE?Set output mode where MODE is one of:

csvComma-separated values

columnLeft-aligned columns.(See .width)

htmlHTML <table> code

insertSQL insert statements for TABLE

lineOne value per line

listValues delimited by .separator string

tabsTab-separated values

tclTCL list elements

.nullvalue STRINGPrint STRING in place of NULL values

.output FILENAMESend output to FILENAME

.output stdoutSend output to the screen

.prompt MAIN CONTINUEReplace the standard prompts

.quitExit this program

.read FILENAMEExecute SQL in FILENAME

.schema ?TABLE?Show the CREATE statements

.separator STRINGChange separator used by output mode and .import

.showShow the current values for various settings

.tables ?PATTERN?List names of tables matching a LIKE pattern

.timeout MSTry opening locked tables for MS milliseconds

.timer ON|OFFTurn the CPU timer measurement on or off

.width NUM NUM ...Set column widths for "column" mode

常用的一些命令解析:

创建表: create table table_name(filed1Name filed1Property,filed2Name filed2Property);

显示数据库中的表:.table

显示表结构:.schema table_name

删除表: .drop table table_name

退出:.exit

显示表所有内容: .dump table_name


导入数据:将txt文件中的数据到导入到表中, data.txt中每一列用”|”分隔, |两边不要空格,文件末尾不要有空行,例如:1|rainkey|tencent

注意:在android 上面执行的时候将text_name.txt存放到databases所在目录

.import text_name.txt table_name


插入记录:insert into table_name values(key,value);

查找记录:select * from table_name;

从第三行开始查询10条记录:select * from table_name limit 3,10;

删除记录:delete from table_name where field1=value;

更新操作:update table_name set name=rainkey where id=1;

参考文档:http://www.pin5i.com/showtopic-android-sqlite3-command-line.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值