maxos下启动sqlite数据库直接启动终端输入sqlite3即可
1. 创建数据库、表的语句:
to create a new SQLite database named "ex1" with a single table named "tbl1", you might do this:
$ sqlite3 ex1
SQLite version 3.6.11
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> create table tbl1(one varchar(10), two smallint);
sqlite> insert into tbl1 values('hello!',10);
sqlite> insert into tbl1 values('goodbye', 20);
sqlite> select * from tbl1;
hello!|10
goodbye|20
sqlite>
注意每个sql命令的结尾处务必加上分号!
2. 接上面的注意事项:
Make sure you type a semicolon at the end of each SQL command! The sqlite3 program looks for a semicolon to know when your SQL command is complete. If you omit the semicolon, sqlite3 will give you a continuation prompt and wait for you to enter more text to be added to the current SQL command. This feature allows you to enter SQL commands that span multiple lines. For example:
sqlite> CREATE TABLE tbl2 (
...> f1 varchar(30) primary key,
...> f2 text,
...> f3 real
...> );
sqlite>
3. sqlite特殊命令:
For a listing of the available dot commands, you can enter ".help" at any time. For example:
sqlite> .help
.backup ?DB? FILE Backup DB (default "main") to FILE
.bail ON|OFF Stop after hitting an error. Default OFF
.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.
.genfkey ?OPTIONS? Options are:
--no-drop: Do not drop old fkey triggers.
--ignore-errors: Ignore tables with fkey errors
--exec: Execute generated SQL immediately
See file tool/genfkey.README in the source
distribution for further information.
.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
.iotrace FILE Enable I/O diagnostic logging to FILE
.load FILE ?ENTRY? Load an extension library
.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
.restore ?DB? FILE Restore content of DB (default "main") from FILE
.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
.timer ON|OFF Turn the CPU timer measurement on or off
.width NUM NUM ... Set column widths for "column" mode
sqlite>
4. 格式化输出结果的写法就不说了,什么时候要用直接查官网文档!
5. Querying the database schema,这个比较常用:
to see a list of the tables in the database, you can enter ".tables".
sqlite> .tables
tbl1
tbl2
sqlite>
查看索引是类似的,不多说,使用 ".indices" command
the ".schema" command shows the original CREATE TABLE and CREATE INDEX statements that were used to build the current database. If you give the name of a table to ".schema", it shows the original CREATE statement used to make that table and all if its indices.
sqlite> .schema
create table tbl1(one varchar(10), two smallint)
CREATE TABLE tbl2 (
f1 varchar(30) primary key,
f2 text,
f3 real
)
sqlite> .schema tbl2
CREATE TABLE tbl2 (
f1 varchar(30) primary key,
f2 text,
f3 real
)
sqlite>
The ".databases" command shows a list of all databases open in the current connection. There will always be at least 2. The first one is "main", the original database opened. The second is "temp", the database used for temporary tables. There may be additional databases listed for databases attached using the ATTACH statement. The first output column is the name the database is attached with, and the second column is the filename of the external file.
sqlite> .databases
6. 重命名表名
alter table current_table_name rename to new_table_name;
7. 修改表结构,添加一个字段
alter table table_name add column column_name column_type;
============================
That's All!
分享到:
相关推荐
常用命令参考: 输出 HTML 表格: sqlite3 -html film.db "select * from film;" 将数据库「倒出来」: sqlite3 film.db ".dump" > output.sql 利用输出的资料,建立一个一模一样的数据库(加上以上指令,就是...
一些常用的SQlite3命令的使用,快速掌握SQlite3的应用。包括创建数据库、表,插入数据等。
ubuntu下安装sqlite3直接在终端运行命令:#apt-get install sqlite3查看版本信息:#sqlite3 -version2 、sqlite3常用命令当前目录下建立或打开test.db数据库文件,并进入sqlite命令终端,以sqlite>前缀标识:#sqlite...
系统平台:ubuntu10.04 简介 ...2 、sqlite3常用命令 当前目录下建立或打开test.db数据库文件,并进入sqlite命令终端,以sqlite>前缀标识: #sqlite3 test.db 查看数据库文件信息命令(注意命令前
3、建立数据表create table table_name(field1 type1, field2 type1, ...) 5、修改数据UPDATE 表 S
vf数据库常用命令开发SQLite数据库常用的管理工具[文].pdf
很多东西能共享就共享了,让更多人学习才是好的。
android开发中,sqlite常用命令使用,欢迎下载...
这是关于sqlite3的一些系统命令以及sql常用语句(包括增删改查)以及函数中可以调用的sqlite3接口
常用命令,数据库的备份和恢复,SQL 使用实例,group by子句
常用命令: 1. .table 列取该数据库下面的数据表名 2. .schema 或者 .schema + 表名 获取整个或者是单个表的表结构 3. .database 显示该数据库所在的位置 4. .dump 显示数据库的所有信息(包括表结构,表...
按F5更新架构树,双击一个表或视图来显示它的数据,使用常用的命令的上下文菜单。 2、网格单元格编辑 表格单元格中编辑:显示一个表通过树状架构,选择一个单元格,然后按F2键调用编辑器。然后修改并确认您的更改写...
主要介绍了一些很有用的SQLite命令总结,本文总结了显示表结构、获取所有表和视图、获取指定表的索引列表、导出数据库到 SQL 文件、从 SQL 文件导入数据库等一些非常有用的操作命令,需要的朋友可以参考下
Sqlite数据库简介 SQLite3数据库的操作 在SQLite中执行常用SQL语句 用sqlite命令管理数据库
按F5更新架构树,双击一个表或视图来显示它的数据,使用常用的命令的上下文菜单。 2、网格单元格编辑:表格单元格中编辑,显示一个表通过树状架构,选择一个单元格,然后按F2键调用编辑器。然后修改并确认您的更改...
教程,安装,命令,语法,数据类型,创建数据库,附加数据库,分离数据库,创建表,删除表,insert语句,select语句,运算符,表达式,where子句,and/or运算符,update子句,like, group,limit, order by, having ...
SQLite的安装下载,及常用的命令.SQLite高度便携、使用方便、结构紧凑、高效、可靠
下面的方法是比较简单且常用的SQLite数据库备份方式,见如下步骤: 1). 使用SQLite API或Shell工具在源数据库文件上加共享锁。 2). 使用Shell工具(cp或copy)拷贝数据库文件到备份目录。 3). 解除数据库文件上的...
言归正传吧,在SQLite的官方下载网站,提供了支持多个平台的命令行工具,使用该工具我们可以完成大多数常用的SQLite操作,就像sqlplus之于Oracle。以下列表给出了该工具的内置命令: 命令名 命令说明 .help 列...