Raspberry Pi

Getting started with SQLite on Raspberry Pi

When you visit the different dynamic websites for example for shopping for something you went on an Amazon website and buy something, at the backend of the website, there is something where all the data of inventory is being managed and stored. These are called databases that stored the data and information of the website, and SQLite is one of these database management systems.

SQLite is a relational database which means it stores the data in the form of structured tables and in this write-up, we will learn the installation method of SQLite on Raspberry Pi as well as different methods to use SQLite.

How to install SQLite on Raspberry Pi

We will check the availability of the SQLite package in the default repository by using the command:

$ apt show sqlite3

After confirming the availability of SQLite, we will install the package of SQLite from the default repository by using the command:

$ sudo apt install sqlite3 -y

To confirm the installation of the SQLite on the Raspberry Pi, we will confirm its version using the command:

$ sqlite --version

How to launch SQLite on Raspberry Pi

After the installation of SQLite from the package available in the default repository, we will use the mentioned-below command to launch the environment of SQLite:

$ sudo sqlite3

To quit the SQLite environment, use the command:

.quit

How to create create a database in SQLite on Raspberry Pi

We will create a database of the name “LinuxHint”, you can change the name with your database name using the same command in the terminal:

$ sudo sqlite3 LinuxHint.db;

How to create and show tables in SQLite on Raspberry Pi

We will create a table with the name of myEmployees using the command:

CREATE TABLE myEmployees (emp_id INT, emp_name CHAR);

And to display the tables in SQLite, use the command:

.tables

How to insert data in tables of SQLite on Raspberry Pi

To insert the data in the table, myEmployees, we will use the command:

INSERT INTO myEmployees VALUES (1, ‘John’), (2, ‘Sara’);

How to display the table in SQLite on Raspberry Pi

To display the table, we will use the command:

SELECT * FROM myEmployees;

How to delete the table in SQLite on Raspberry Pi

To delete the table we will use the drop command:

DROP TABLE myEmployes;

To confirm the deletion of table, we will display the tables:

.tables

The table has been deleted successfully.

Conclusion

SQLite is a relational database that stores the data of dynamic websites and different web applications in structured tabular form. In this blog, the installation of SQLite on Raspberry Pi as well as some important usage of the SQLite has been explained using the Raspberry Pi operating system.

About the author

Hammad Zahid

I'm an Engineering graduate and my passion for IT has brought me to Linux. Now here I'm learning and sharing my knowledge with the world.