ATTACH DATABASE
BEGIN TRANSACTION
comment
COMMIT TRANSACTION
COPY
CREATE INDEX
CREATE TABLE
CREATE TRIGGER
CREATE VIEW
DELETE
DETACH DATABASE
DROP INDEX
DROP TABLE
DROP TRIGGER
DROP VIEW
END TRANSACTION
EXPLAIN
expression
INSERT
ON CONFLICT clause
PRAGMA
REPLACE
ROLLBACK TRANSACTION
SELECT
UPDATE
下载windows下的文件,其实就是一个命令行程序,(下载地址:http://www.sqlite.org/sqlite-3_2_2.zip),这个命令行程序用来包括生成数据库文件、执行SQL查询、备份数据库等等功能。
下载后比如我们解压缩到 D:\Downloads\sqlite\sqlite-3_2_2 这个目录下,那么我们进入cmd,并且进入该目录:
cd D:\Downloads\sqlite\sqlite-3_2_2
D:\Downloads\sqlite\sqlite-3_2_2>sqlite3 test.db
# 如果test.db不存在,那么就产生一个数据库文件,如果存在就直接使用该数据库文件,相当于mysql中的use
SQLite version 3.2.2
Enter ".help" for instructions
sqlite>
# SQLite的提示符,如果想查看命令帮助输入 .help,在sqlite中所有系统命令都是 . 开头的:
sqlite> .help
.databases List names and files of attached databases
.dump ?TABLE? ... Dump the database in an SQL text format
.echo ON|OFF Turn command echo on or off
.exit Exit this program
.explain ON|OFF Turn output mode suitable for EXPLAIN on or off.
.header(s) ON|OFF Turn display of headers on or off
.help Show this message
.import FILE TABLE Import data from FILE into TABLE
.indices TABLE Show names of all indices on TABLE
.mode MODE ?TABLE? Set output mode where MODE is one of:
csv Comma-separated values
column Left-aligned columns. (See .width)
html HTML <table> code
insert SQL insert statements for TABLE
line One value per line
list Values delimited by .separator string
tabs Tab-separated values
tcl TCL list elements
.nullvalue STRING Print STRING in place of NULL values
.output FILENAME Send output to FILENAME
.output stdout Send output to the screen
.prompt MAIN CONTINUE Replace the standard prompts
.quit Exit this program
.read FILENAME Execute SQL in FILENAME
.schema ?TABLE? Show the CREATE statements
.separator STRING Change separator used by output mode and .import
.show Show the current values for various settings
.tables ?PATTERN? List names of tables matching a LIKE pattern
.timeout MS Try opening locked tables for MS milliseconds
.width NUM NUM ... Set column widths for "column" mode
sqlite>
www.knowsky.com
# 我们创建一个数据库catlog
sqlite> create table catalog(
...> id integer primarykey,
...> pid integer,
...> name varchar(10) UNIQUE
...> );
sqlite>
# 如果表存在就会提示:
SQL error: table catalog already exists
# 我们创建索引信息
create index catalog_idx on catalog (id asc);
# 我们查看表的信息,看有多少个表
sqlite> .table
aa catalog
# 查看表的结构:
sqlite> .schema catalog
CREATE TABLE catalog(
id integer primary key,
pid integer,
name varchar(10) UNIQUE
);
CREATE INDEX catalog_idx on catalog(id asc);
# 给数据表插入一条记录
sqlite> insert into catalog (ppid,name) values ('001','heiyeluren');
# 成功无任何提示,如果表达式错误提示错误信息:
SQL error: near "set": syntax error
# 检索有多少条记录
sqlite> select count(*) from catalog;
1
# 检索搜索记录
sqlite> select * from catalog;
1|1|heiyeluren