1.SQLITE common commands
SQLite sqlite commands are called common point command, except that they do not command the semicolon; end.
Type a simple command sqlite3 command us just on ubuntu terminal interface prompt $ in the SQLite command prompt> down, you can use various SQLite command as follows:
To obtain a list of commands sqlite, you can use .help command. .Help execute command you can get the following information:
can learn sqlite command name from the parts list, using the format and function.
2.sqlite most commonly used commands carding
1 from the list of commands in the command sqlite know there are many, but not all of the command will use or frequent use. Next, the sort commonly used commands, and actual operation to be verified. Suppose the existence of the database demo, there is a company database table records the basic information of employees (ID, name, age, address, salary). As follows (in the case where the output format is not provided):
- Display various setting -----.show command current value
if the need to change the current setting value, use the appropriate commands, as: Let modify data in the database table formatted output:
on or off CPU Timer - ---. timer on / off
to set the output mode ----. mode command to
turn on or off the headers command -.header
- And the name of the attached file list database -------. Database command
- It lists the current database where all tables attached -----. Table command
- 显示表格结构 -----.schema命令
-退出 SQLite 提示符>----.exit命令
note:.quit命令与.exit命令作用相同
-命令行命令回显功能设置—echo on/off命令
- 导入来自 FILE 文件的数据到 TABLE 表中—.import FILE TABLE命令
注1: 不要忘了开头的点
注2: 这条语句不能用分号结束. 非SQL不需要分号结束.
注3: 需要查看默认的分隔符separator. 必须一致. 如果不一致可能导致sqlite字段分割错误.
三个注意具体体现在下面几个容易出错的地方:
1)导入的文件中的内容要与目标表的属性相同,如:文件中的内容为9,xiaoming,40,wuhanlu,10000.00
对应于表的id,name,age,adderss,salary,并且字段以逗号分割。
2).import file table后不能加;否则会出错,弹出下面的信息:
3)改变输出模式和 .import 所使用的分隔符,在进行.import操作前必须使用.separator命令设置分隔符
,否则会弹出如下错误信息:
- 发送输出到 FILENAME 文件—.output filename命令
-以 SQL 文本格式转储数据库—.dump命令
note:如果.dump后指定了 TABLE 表,则只转储匹配 LIKE 模式的 TABLE 表 - 执行 FILENAME 文件中的 SQL----.read命令
Deriving a single file table data to do the following:
the need to use the command: .OUTPUT
1)sqlite> .output a.txt
2) Then enter sql statement, check out the guide to the data. After the inquiry, the data will not be displayed on the screen, and writing files.
When finished, enter
3)sqlite> .output stdout
4) to redirect output to the screen.
For example: export data to a file a.txt tab_xx
sqlite> .output a.txt
sqlite> select * from tab_xx;
sqlite> .output stdout
Export all database to a sql file
sqlite3 data.db
sqlite>.output dd.sql
sqlite>.dump
The contents of a sql file in all other import a database
sqlite3 mydb.db
sqlite>.read dd.sql
That part of the above explanation and verification of several commonly used commands, other commands do subsequent use to supplement the time.