文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>sqlite简介

sqlite简介

时间:2009-05-24  来源:FreedomXura

SQLite是一款轻型数据库,它的的设计目标是嵌入式的,而且目前已经在很多嵌入式产品中使用了它,它占用资源非常的低,在嵌入式设备中,可能只需要几百K的内存就够了。它能够支持Windows/Linux/Unix等等主流操作系统,同时能够跟很多程序语言相结合,比如Tcl,java,php,还有ODBC接口,同样比起mysql,PostgreSQL这两款开源著名的数据库管理系统来讲,它的处理速度比他们都快。

SQLite虽然很小巧,但是支持的SQL语句不会逊色于其他开源数据库,它支持的SQL包括:

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

简单使用:
>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>
# 我们创建一个数据库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

反正使用标准的SQL来操作就没有问题,不清楚可以去官方网站上查看帮助信息。另外还要说明的是SQLite不支持修改表结构,如果要修改表结构,只有删除表重新再建立,所以建立表的时候一定要考虑扩展性。估计以后这方面的功能会加强。

More information:

http://www.sqlite.org/docs.html
http://www.sqlite.org/lang.html
相关阅读 更多 +
排行榜 更多 +
Unity Connect

Unity Connect

学习教育 下载
青橙记录本

青橙记录本

商务办公 下载
脑洞惊魂夜

脑洞惊魂夜

休闲益智 下载