Common SQLite Commands and Common Errors
Command | Description |
| Display all available SQLite commands. |
| List all tables in the database. |
| Display the SQL schema (table definitions). |
| Show attached databases and file locations. |
| Display column names in query results. |
| Format query results in columns for readability. |
| List indexes defined in the database. |
| Export the database contents as SQL statements. |
| Create a backup of the database. |
| Restore a database from a backup file. |
| Import data from a file into a table. |
| Open query results in a spreadsheet. |
| Display database performance statistics. |
| Display execution time for SQL statements. |
| Show SQLite version information. |
| Exit SQLite and return to the Linux shell. |
Common SQL Queries
Display all records from a table:
SELECT * FROM users;Display selected columns:
SELECT id, name FROM users;Count the number of rows:
SELECT COUNT(*) FROM users;Example Session
sqlite3 test.db.tables
.schema
.headers on
.mode column
SELECT * FROM users;
.quitCommon Errors and Troubleshooting
Depending on how users interact with the database on chip, errors may appear in different places:
Python errors will appear when running a Python script (
python database.py) or while using the interactive Python interpreter.Linux command-line (CLI) errors will appear directly in the terminal when executing commands such as
mkdir,cd,pwd, or attempting to use unavailable software.Storage and permission errors may occur when creating or writing database files in locations where you do not have sufficient permissions or when your home directory storage quota is full.
Errors
Error or Message | Where the user would see it | Cause | Solution |
|---|---|---|---|
| Linux shell/terminal | Python code was typed in the Linux shell | Run |
| Python prompt | Explanation text or shell commands were typed into Python | Only type Python code at the |
| Python prompt | A shell command was typed inside Python | Exit Python using |
| Linux shell/terminal | SQLite CLI is not available in the current environment | Use Method A or activate a Conda environment that provides |
| Linux shell/terminal after | Conda environment name does not exist | Run |
| Python script or Python prompt | Table was not created before querying | Run the |
| Python prompt after querying | Database exists but contains no tables | Create a table first |
Data missing after reopening | Python method | Changes were not committed before closing | Run |
| Python prompt or SQLite CLI | Table was created during a previous test | Delete the old database file or use a new database name |
| Python prompt or SQLite CLI during insert | Duplicate primary key values were inserted | Use a new database file or unique IDs |
| Python, SQLite CLI, or Linux shell while writing files | Home directory is full | Use PI/project storage instead of the home directory |
| Python prompt or script | Incorrect path or insufficient permissions | Check |
| Linux shell/terminal | Directory path does not exist | Create the directory with |
| Linux shell/terminal after | Requested software module is unavailable | Use Python |
Notes for Users:
SQLite databases are normal files ending in
.db.Using PI/project storage is recommended if the home directory is full.
For beginner tests, the login node is acceptable.
For large database work, use a compute node.