{"id":33061,"date":"2017-02-09T13:42:48","date_gmt":"2017-02-09T13:42:48","guid":{"rendered":"http:\/\/randomnerdtutorials.com\/?p=33061"},"modified":"2019-06-03T10:48:41","modified_gmt":"2019-06-03T10:48:41","slug":"sqlite-database-on-a-raspberry-pi","status":"publish","type":"post","link":"https:\/\/randomnerdtutorials.com\/sqlite-database-on-a-raspberry-pi\/","title":{"rendered":"SQLite Database on a Raspberry Pi"},"content":{"rendered":"<p>In this blog post I&#8217;ll introduce you to SQLite, which is an in-process light weight library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine. SQLite is the most widely deployed SQL database engine in the world\u00a0and its source code is in the public domain.<!--more--><\/p>\n<p><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter wp-image-33067\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/Home-Automation-Raspberry-Pi-MQTT.jpg?resize=701%2C394&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"701\" height=\"394\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/Home-Automation-Raspberry-Pi-MQTT.jpg?w=1280&amp;quality=100&amp;strip=all&amp;ssl=1 1280w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/Home-Automation-Raspberry-Pi-MQTT.jpg?resize=150%2C84&amp;quality=100&amp;strip=all&amp;ssl=1 150w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/Home-Automation-Raspberry-Pi-MQTT.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/Home-Automation-Raspberry-Pi-MQTT.jpg?resize=768%2C432&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/Home-Automation-Raspberry-Pi-MQTT.jpg?resize=1024%2C576&amp;quality=100&amp;strip=all&amp;ssl=1 1024w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/Home-Automation-Raspberry-Pi-MQTT.jpg?resize=80%2C45&amp;quality=100&amp;strip=all&amp;ssl=1 80w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/Home-Automation-Raspberry-Pi-MQTT.jpg?resize=220%2C124&amp;quality=100&amp;strip=all&amp;ssl=1 220w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/Home-Automation-Raspberry-Pi-MQTT.jpg?resize=178%2C100&amp;quality=100&amp;strip=all&amp;ssl=1 178w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/Home-Automation-Raspberry-Pi-MQTT.jpg?resize=267%2C150&amp;quality=100&amp;strip=all&amp;ssl=1 267w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/Home-Automation-Raspberry-Pi-MQTT.jpg?resize=423%2C238&amp;quality=100&amp;strip=all&amp;ssl=1 423w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/Home-Automation-Raspberry-Pi-MQTT.jpg?resize=738%2C415&amp;quality=100&amp;strip=all&amp;ssl=1 738w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/Home-Automation-Raspberry-Pi-MQTT.jpg?resize=866%2C487&amp;quality=100&amp;strip=all&amp;ssl=1 866w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/Home-Automation-Raspberry-Pi-MQTT.jpg?resize=1058%2C595&amp;quality=100&amp;strip=all&amp;ssl=1 1058w\" sizes=\"(max-width: 701px) 100vw, 701px\" \/><\/p>\n<p>Don&#8217;t have a <a href=\"https:\/\/makeradvisor.com\/raspberry-pi-board\/\" target=\"_blank\" rel=\"noopener noreferrer\">Raspberry Pi board<\/a>? read\u00a0<a href=\"https:\/\/makeradvisor.com\/best-raspberry-pi-3-starter-kits\/\" target=\"_blank\" rel=\"noopener noreferrer\">Best Raspberry Pi Starter Kits.<\/a><\/p>\n<h2>What is SQLite?<\/h2>\n<p><a href=\"https:\/\/www.sqlite.org\/\" target=\"_blank\" rel=\"noopener noreferrer\">SQLite<\/a> is an embedded SQL database engine. Unlike most other SQL databases, SQLite does not have a separate server process. SQLite reads and writes directly to ordinary disk files. A complete SQL database with multiple tables, indices, triggers, and views, is contained in a single disk file.<\/p>\n<p><img data-recalc-dims=\"1\" decoding=\"async\" class=\"aligncenter wp-image-33068\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/SQLite370.svg_.png?resize=313%2C148&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"313\" height=\"148\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/SQLite370.svg_.png?w=400&amp;quality=100&amp;strip=all&amp;ssl=1 400w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/SQLite370.svg_.png?resize=150%2C71&amp;quality=100&amp;strip=all&amp;ssl=1 150w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/SQLite370.svg_.png?resize=300%2C142&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/SQLite370.svg_.png?resize=80%2C38&amp;quality=100&amp;strip=all&amp;ssl=1 80w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/SQLite370.svg_.png?resize=220%2C104&amp;quality=100&amp;strip=all&amp;ssl=1 220w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/SQLite370.svg_.png?resize=212%2C100&amp;quality=100&amp;strip=all&amp;ssl=1 212w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/SQLite370.svg_.png?resize=280%2C132&amp;quality=100&amp;strip=all&amp;ssl=1 280w\" sizes=\"(max-width: 313px) 100vw, 313px\" \/><\/p>\n<p>This tutorial shows you how to install SQLite on a Raspberry Pi and teach you some basic commands to use SQLite in your RPi projects.<\/p>\n<p><strong>Note:<\/strong> SQLite is more powerful and has a lot more features from what I&#8217;m about to show you, however the purpose of this tutorial is to share a basic example on how you would store temperature and humidity readings in a SQLite table. For more information you can read the official documentation <a href=\"https:\/\/www.sqlite.org\/docs.html\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a>.<\/p>\n<h2>Basic Raspberry Pi Setup<\/h2>\n<p>Before you continue reading this project, please\u00a0make sure you have Raspbian Operating System installed in your <a href=\"https:\/\/makeradvisor.com\/raspberry-pi-board\/\" target=\"_blank\" rel=\"noopener noreferrer\">Raspberry Pi<\/a>.<\/p>\n<p>You can read my <strong><a href=\"https:\/\/randomnerdtutorials.com\/getting-started-with-raspberry-pi\/\">Getting Started with the Raspberry Pi Guide<\/a><\/strong>\u00a0to install Raspbian and complete the basic setup.<\/p>\n<h2>Why SQLite?<\/h2>\n<p>Here&#8217;s some of the features that makes SQLite a great database:<\/p>\n<ul>\n<li>A complete SQLite database is stored in a single cross-platform disk file<\/li>\n<li>SQLite is very small and light weight<\/li>\n<li>SQLite is self-contained\u00a0(no external dependencies required)<\/li>\n<li>SQLite does not require a separate server process or system to operate (serverless)<\/li>\n<li>SQLite comes with zero-configuration (no setup\u00a0needed)<\/li>\n<li>SQLite is cross-platform. It&#8217;s available on UNIX (Linux, Mac OS-X, Android, iOS) and Windows (Win32, WinCE, WinRT)<\/li>\n<\/ul>\n<p>Databases are used to store information\u00a0in a way that can be accessed quickly and easily.\u00a0In this post you&#8217;re going to build a data logging application with a Raspberry Pi that stores temperature and humidity.<\/p>\n<h2>Installing SQLite on Raspberry Pi<\/h2>\n<p><img data-recalc-dims=\"1\" decoding=\"async\" class=\"aligncenter size-full wp-image-33069\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/SQLite-Raspberry-Pi.jpg?resize=712%2C197&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"712\" height=\"197\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/SQLite-Raspberry-Pi.jpg?w=712&amp;quality=100&amp;strip=all&amp;ssl=1 712w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/SQLite-Raspberry-Pi.jpg?resize=150%2C42&amp;quality=100&amp;strip=all&amp;ssl=1 150w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/SQLite-Raspberry-Pi.jpg?resize=300%2C83&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/SQLite-Raspberry-Pi.jpg?resize=80%2C22&amp;quality=100&amp;strip=all&amp;ssl=1 80w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/SQLite-Raspberry-Pi.jpg?resize=220%2C61&amp;quality=100&amp;strip=all&amp;ssl=1 220w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/SQLite-Raspberry-Pi.jpg?resize=250%2C69&amp;quality=100&amp;strip=all&amp;ssl=1 250w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/SQLite-Raspberry-Pi.jpg?resize=280%2C77&amp;quality=100&amp;strip=all&amp;ssl=1 280w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/SQLite-Raspberry-Pi.jpg?resize=510%2C141&amp;quality=100&amp;strip=all&amp;ssl=1 510w\" sizes=\"(max-width: 712px) 100vw, 712px\" \/><\/p>\n<p>You can install SQLite on a Raspberry Pi using this command:<\/p>\n<pre>pi@raspberry:~ $ <strong>sudo apt-get install sqlite3<\/strong><\/pre>\n<p>You\u2019ll have to type <strong>Y<\/strong> and press <strong>Enter<\/strong> to confirm the installation.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-33085\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/installting-sqlite.png?resize=604%2C265&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"604\" height=\"265\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/installting-sqlite.png?w=812&amp;quality=100&amp;strip=all&amp;ssl=1 812w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/installting-sqlite.png?resize=150%2C66&amp;quality=100&amp;strip=all&amp;ssl=1 150w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/installting-sqlite.png?resize=300%2C132&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/installting-sqlite.png?resize=768%2C337&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/installting-sqlite.png?resize=80%2C35&amp;quality=100&amp;strip=all&amp;ssl=1 80w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/installting-sqlite.png?resize=220%2C96&amp;quality=100&amp;strip=all&amp;ssl=1 220w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/installting-sqlite.png?resize=228%2C100&amp;quality=100&amp;strip=all&amp;ssl=1 228w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/installting-sqlite.png?resize=280%2C123&amp;quality=100&amp;strip=all&amp;ssl=1 280w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/installting-sqlite.png?resize=510%2C224&amp;quality=100&amp;strip=all&amp;ssl=1 510w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/installting-sqlite.png?resize=750%2C329&amp;quality=100&amp;strip=all&amp;ssl=1 750w\" sizes=\"(max-width: 604px) 100vw, 604px\" \/><\/p>\n<p>After the installation is completed, the SQLite libraries are supplied with an SQLite shell. Use\u00a0this next command to invoke the shell and create a database:<\/p>\n<pre>pi@raspberry:~ $ <strong>sqlite3 sensordata.db<\/strong><\/pre>\n<p>The file sensordata.db is now\u00a0created. After typing the preceding command, a prompt appears where you\u00a0can enter commands. The shell supports two types of commands. Commands that start with a &#8216;.&#8217; are used to control the shell. Try typing these commands:<\/p>\n<pre>sqlite&gt; <strong>.help<\/strong><\/pre>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-33086\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/sqlite3.png?resize=612%2C376&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"612\" height=\"376\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/sqlite3.png?w=612&amp;quality=100&amp;strip=all&amp;ssl=1 612w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/sqlite3.png?resize=150%2C92&amp;quality=100&amp;strip=all&amp;ssl=1 150w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/sqlite3.png?resize=300%2C184&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/sqlite3.png?resize=80%2C49&amp;quality=100&amp;strip=all&amp;ssl=1 80w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/sqlite3.png?resize=220%2C135&amp;quality=100&amp;strip=all&amp;ssl=1 220w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/sqlite3.png?resize=163%2C100&amp;quality=100&amp;strip=all&amp;ssl=1 163w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/sqlite3.png?resize=244%2C150&amp;quality=100&amp;strip=all&amp;ssl=1 244w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/sqlite3.png?resize=387%2C238&amp;quality=100&amp;strip=all&amp;ssl=1 387w\" sizes=\"(max-width: 612px) 100vw, 612px\" \/><\/p>\n<p>With the &#8216;<strong>.help<\/strong>&#8216; command you can be quickly reminded of all the supported commands and their respective usage.<\/p>\n<p>To\u00a0quit from the SQLite shell use the &#8216;<strong>.quit<\/strong>&#8216; command.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-33087\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/sensordata.db-file.png?resize=180%2C69&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"180\" height=\"69\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/sensordata.db-file.png?w=180&amp;quality=100&amp;strip=all&amp;ssl=1 180w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/sensordata.db-file.png?resize=150%2C58&amp;quality=100&amp;strip=all&amp;ssl=1 150w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/sensordata.db-file.png?resize=80%2C31&amp;quality=100&amp;strip=all&amp;ssl=1 80w\" sizes=\"(max-width: 180px) 100vw, 180px\" \/><\/p>\n<p><strong>Note:<\/strong> you can use the up arrow to scroll through previous commands.<\/p>\n<p>The shell also supports SQL commands which you&#8217;re going to try in the next section.<\/p>\n<h2>Using SQL to access databases<\/h2>\n<p>Structured Query Language (SQL) is a language that&#8217;s used for interacting with databases. It can be used to create tables, insert, update, delete and search for data.<\/p>\n<p>SQL works with different database solutions such as SQLite, MySQL and others. SQL statements must end with a semicolon\u00a0(;).<\/p>\n<p>It&#8217;s common for SQL commands to be capitalized, but this isn&#8217;t strictly necessary. Most people prefer to use capitalized letters, because it increases readability.<\/p>\n<h3>SQL CREATE TABLE<\/h3>\n<p>I&#8217;m going to start by creating a simple table with 6 columns that could be used for temperature\u00a0and humidity logging application in different parts of a home. Let&#8217;s start by creating a\u00a0table:<\/p>\n<pre>sqlite&gt; <strong>BEGIN;<\/strong>\nsqlite&gt; <strong>CREATE TABLE dhtreadings(id INTEGER PRIMARY KEY AUTOINCREMENT, temperature NUMERIC, humidity NUMERIC, currentdate DATE, currentime TIME, device TEXT);<\/strong>\nsqlite&gt; <strong>COMMIT;<\/strong><\/pre>\n<p>To see all the tables, type:<\/p>\n<pre>sqlite&gt; <strong>.tables<\/strong>\ndhtreadings<\/pre>\n<p>It returns the newly created table named &#8216;dhtreadings&#8217;. You can see the fullschema of the tables when you enter:<\/p>\n<pre>sqlite&gt; <strong>.fullschema<\/strong>\nCREATE TABLE dhtreadings(id INTEGER PRIMARY KEY AUTOINCREMENT, temperature NUMERIC, humidity NUMERIC, currentdate DATE, currentime TIME, device TEXT);<\/pre>\n<h3>SQL INSERT<\/h3>\n<p>To insert new temperature and humidity readings in the database, you could do something like this:<\/p>\n<pre>sqlite&gt; <strong>BEGIN;<\/strong>\nsqlite&gt; <strong>INSERT INTO dhtreadings<span class=\"pun\">(temperature<\/span><span class=\"pun\">,<\/span><span class=\"pln\"> humidity<\/span><span class=\"pun\">, currentdate<\/span><span class=\"pun\">, currentime, device)<\/span><span class=\"pun\">\u00a0<\/span>values(22.4, 48, date('now'), time('now'), \"manual\");<\/strong>\nsqlite&gt; <strong>COMMIT;<\/strong><\/pre>\n<p>In a future blog post, the ESP8266 is going to send the readings to a Python web server that inserts the data in the table.<\/p>\n<h3>SQL SELECT<\/h3>\n<p>To access the data stored in the database, you use the SELECT SQL statement:<\/p>\n<pre>sqlite&gt; <strong>SELECT * FROM dhtreadings;<\/strong>\n1|22.4|48|2017-01-26|23:43:13|manual<\/pre>\n<p>So far, you only have 1 reading inserted in the database. You can insert a new\u00a0reading as follows:<\/p>\n<pre>sqlite&gt; <strong>BEGIN;<\/strong>\nsqlite&gt; <strong>INSERT INTO dhtreadings<span class=\"pun\">(temperature<\/span><span class=\"pun\">,<\/span><span class=\"pln\"> humidity<\/span><span class=\"pun\">, currentdate<\/span><span class=\"pun\">, currentime, device)<\/span><span class=\"pun\">\u00a0<\/span>values(22.5, 48.7, date('now'), time('now'), \"manual\");<\/strong>\nsqlite&gt; <strong>COMMIT;<\/strong><\/pre>\n<p>And when you SELECT the data stored in the table, it returns 2 readings:<\/p>\n<pre>sqlite&gt; <strong>SELECT * FROM dhtreadings;<\/strong>\n1|22.4|48|2017-01-26|23:43:13|manual\n2|22.5|48.7|2017-01-26|23:43:54|manual<\/pre>\n<p>For an easier understanding, you can compare a SQL table to an Excel sheet that looks like this:<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-33091\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/spreadsheet_example.png?resize=643%2C100&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"643\" height=\"100\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/spreadsheet_example.png?w=643&amp;quality=100&amp;strip=all&amp;ssl=1 643w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/spreadsheet_example.png?resize=150%2C23&amp;quality=100&amp;strip=all&amp;ssl=1 150w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/spreadsheet_example.png?resize=300%2C47&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/spreadsheet_example.png?resize=80%2C12&amp;quality=100&amp;strip=all&amp;ssl=1 80w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/spreadsheet_example.png?resize=220%2C34&amp;quality=100&amp;strip=all&amp;ssl=1 220w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/spreadsheet_example.png?resize=250%2C39&amp;quality=100&amp;strip=all&amp;ssl=1 250w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/spreadsheet_example.png?resize=280%2C44&amp;quality=100&amp;strip=all&amp;ssl=1 280w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/spreadsheet_example.png?resize=510%2C79&amp;quality=100&amp;strip=all&amp;ssl=1 510w\" sizes=\"(max-width: 643px) 100vw, 643px\" \/><\/p>\n<h3>SQL DROP<\/h3>\n<p>If you want to completely delete the table from your database, you can use the DROP TABLE command.<\/p>\n<p><strong><span style=\"color: #ff0000;\">Warning:<\/span> <\/strong>the next command will\u00a0completely delete the dhtreadings table:<\/p>\n<pre><span class=\"pln\">sqlite&gt; <strong>DROP TABLE dhtreadings<\/strong><\/span><strong><span class=\"pun\">;<\/span><\/strong><\/pre>\n<p>Now, if you type the &#8216;<strong>.tables<\/strong>&#8216;\u00a0command:<\/p>\n<pre>sqlite&gt; <strong>.tables<\/strong><\/pre>\n<p>It doesn&#8217;t return anything, because your table was completely deleted.<\/p>\n<h2>Wrapping up<\/h2>\n<p>We&#8217;ve just scratched the surface of what you can do with SQLite. Learn how to publish sensor readings with the ESP8266 that will be stored in the database and displayed in your Python web server:<\/p>\n<ul>\n<li><a href=\"https:\/\/randomnerdtutorials.com\/esp8266-publishing-dht22-readings-to-sqlite-database\/\">ESP8266 Publishing DHT22 Readings to SQLite Database<\/a><\/li>\n<\/ul>\n<p>Like home automation? Learn more about Node-RED, Raspberry Pi, ESP8266 and Arduino\u00a0with\u00a0my course:\u00a0<a href=\"https:\/\/randomnerdtutorials.com\/build-a-home-automation-system-for-100\/\" target=\"_blank\" rel=\"noopener noreferrer\">Build a Home Automation System for $100<\/a>.<\/p>\n<p><strong>Do you have any questions?\u00a0<\/strong><strong>Leave a comment down below!<\/strong><\/p>\n<p>Thanks for reading. If you like this post probably you might like my next ones, so please support me by <a href=\"https:\/\/randomnerdtutorials.com\/download\">subscribing my blog<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this blog post I&#8217;ll introduce you to SQLite, which is an in-process light weight library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine. SQLite is the most &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"SQLite Database on a Raspberry Pi\" class=\"read-more button\" href=\"https:\/\/randomnerdtutorials.com\/sqlite-database-on-a-raspberry-pi\/#more-33061\" aria-label=\"Read more about SQLite Database on a Raspberry Pi\">CONTINUE READING \u00bb<\/a><\/p>\n","protected":false},"author":1,"featured_media":33067,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[301,285,269,264,268,287,286],"tags":[],"class_list":["post-33061","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-0-raspberrypi","category-databases","category-guide-project","category-project","category-raspberry-pi-project","category-sql","category-sqlite"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/01\/Home-Automation-Raspberry-Pi-MQTT.jpg?fit=1280%2C720&quality=100&strip=all&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/33061","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/comments?post=33061"}],"version-history":[{"count":0,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/33061\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media\/33067"}],"wp:attachment":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media?parent=33061"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/categories?post=33061"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/tags?post=33061"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}