Difference between revisions of "Search an SQL database using sqlite3"
Line 27: | Line 27: | ||
<syntaxhighlight lang="SQL"> | <syntaxhighlight lang="SQL"> | ||
SELECT * FROM | SELECT * FROM tablename | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 34: | Line 34: | ||
<syntaxhighlight lang="SQL" line> | <syntaxhighlight lang="SQL" line> | ||
.headers ON | .headers ON | ||
.mode | .mode column | ||
</syntaxhighlight> | |||
You will get output like: | |||
<syntaxhighlight lang="SQL" line> | |||
.headers on | |||
.mode column | |||
select * from mytable; | |||
id foo bar | |||
---------- ---------- ---------- | |||
1 val1 val2 | |||
2 val3 val4 | |||
</syntaxhighlight> | |||
You can also display detailed views of the contents of tables, with | |||
<syntaxhighlight lang="SQL" line> | |||
PRAGMA_ | |||
</syntaxhighlight> | </syntaxhighlight> | ||
Revision as of 16:29, 14 November 2021
https://www.sqlite.org/index.html
sqlite
implements a small, fast, self-contained, high-reliability, full-featured, SQL database engine to query .sql
files.
Getting started
To use sqlite, you must have a valid metadata file with a .db
file extension, and an installed version of SQL. This tutorial assumes knowledge of the command line.
To start the sql engine, type:
sqlite3
The prompt will change, showing that the sqlite engine has been initialised. To open a metadata file, type:
.open filename.db
You can then display tables with:
.tables
Based on what is returned, you can then query the content of each table with commands such as:
SELECT * FROM tablename
You may want to have a more human-readable view of the data that is printed in the terminal, by organising the headings and columns:
.headers ON
.mode column
You will get output like:
.headers on
.mode column
select * from mytable;
id foo bar
---------- ---------- ----------
1 val1 val2
2 val3 val4
You can also display detailed views of the contents of tables, with
PRAGMA_