English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
This chapter will guide you through the simple and useful commands used by SQLite programmers. These commands are called SQLite point commands, but the exception is that they should not be terminated with a semicolon (;).
Let's start withsqlite3
Start by entering a simple command at the command prompt, which will provide you with a SQLite command prompt where you can issue various SQLite commands.
$sqlite3 SQLite version 3.3.6 Enter " .help " for instructions sqlite>
For a list of available point commands, you can enter '.help' at any time. For example-
sqlite>.help
The above commands will display a list of various important SQLite point commands. The table below lists these commands.
Number | Command and description |
---|---|
1 |
Backup database (default is 'main') to FILE |
2 |
Stop after encountering an error. Default is off |
3 |
List the names and files of attached databases |
4 |
Dump the database in SQL text format. If TABLE is specified, only dump tables that match the LIKE pattern TABLE |
5 |
Open or close command echoing |
6 |
Exit the SQLite prompt |
7 |
Open or close output mode suitable for EXPLAIN. Without parameters, it will open EXPLAIN |
8 |
Open or close header display |
9 |
Display this message |
10 |
Import data from FILE to TABLE |
11 |
Display the names of all indices. If TABLE is specified, only display indices of tables that match the LIKE pattern TABLE |
12 |
Load extension library |
13 |
Open or close login. FILE can be stderr / stdout |
14 |
Set MODE to one of the following output modes-
|
15 |
Print STRING instead of NULL value |
16 |
Send output to FILENAME |
17 |
Send output to the screen |
18Age |
Print the text STRING |
19 |
Replace the standard prompt |
20 |
Exit the SQLite prompt |
21 |
Execute SQL in FILENAME |
22 |
Display CREATE statements. If TABLE is specified, only tables matching the LIKE pattern TABLE are displayed |
23 |
Change the output mode and the delimiter used by .import |
24 |
Display the current values of various settings |
25 |
Open or close statistics |
26 |
List the names of tables that match the LIKE pattern |
27 |
Try to open a locked table, in milliseconds |
28 |
Set the column width in 'column' mode |
29 |
Open or close CPU timer measurement |
Let's try using.show
Command to view the default settings of the SQLite command prompt.
sqlite>.show echo: off explain: off headers: off mode: column nullvalue: "" output: stdout separator: "|" width: sqlite>
Make sure there are no spaces between the sqlite> prompt and the dot commands, otherwise it will not work properly.
You can use the following dot command sequence to format the output.
sqlite>.header on sqlite>.mode column sqlite>.timer on sqlite>
The above settings will produce the following format of output.
ID NAME AGE ADDRESS SALARY ---------- ---------- ---------- ---------- ---------- 1 Paul 32 California 20000.0 2 Allen 25 Texas 15000.0 3 Teddy 23 Norway 20000.0 4 Mark 25 Rich-Mond 65000.0 5 David 27 Texas 85000.0 6 Kim 22 South-Hall 45000.0 7 James 24 Houston 10000.0 CPU Time: user 0.000000 sys 0.000000
The main table saves key information about the database tables, which is calledsqlite_master
You can see its schema as follows:
sqlite>.schema sqlite_master
This will produce the following result.
CREATE TABLE sqlite_master ( type text, name text, tbl_name text, rootpage integer, sql text);