PRO 30% Free • Stripe ($15) & Razorpay (₹899)

What is SQLite?

Top Course Staff · 4 min read · Web development · PRO · 30% Free Preview Available

What is SQLite?

In this article, we will be exploring the extremely prevalent database engine calledSQLite. We will describe what it does, its main uses, and then explain how to set it up and use it on your own computer.

What is SQLite?

SQLite is a database engine. It is software that allows users to interact with arelational database. In SQLite, a database is stored in a single file — a trait that distinguishes it from other database engines. This fact allows for a great deal of accessibility: copying a database is no more complicated than copying the file that stores the data, sharing a database can mean sending an email attachment.

Drawbacks to SQLite

SQLite’s signature portability unfortunately makes it a poor choice when many different users are updating the table at the same time (to maintain integrity of data, only one user can write to the file at a time). It also may require some more work to ensure the security of private data due to the same features that make SQLite accessible. Furthermore, SQLite does not offer the same exact functionality as many other database systems, limiting some advanced features other relational database systems offer. Lastly, SQLite does not validate data types. Where many other database software would reject data that does not conform to a table’s schema, SQLite allows users to store data of any type into any column.

SQLite creates schemas, which constrain the type of data in each column, but it does not enforce them. The example below shows that the id column expects to store integers, the name column expects to store text, and the age column expects to store integers:

CREATE TABLE celebs (   id INTEGER,    name TEXT,    age INTEGER);
Copy to clipboard
CREATE TABLE celebs (   id INTEGER,    name TEXT,    age INTEGER);

However, SQLite will not reject values of the wrong type. We could accidentally insert the wrong data types in the columns. Storing different data types in the same column is a bad habit that can lead to errors that are difficult to fix, so it’s important to be strict about your schema even though SQLite will not enforce it.

Common use cases for SQLite

Even considering the drawbacks, the benefits of being able to access and manipulate a database without involving a server application are huge. SQLite is used worldwide for testing, development, and in any other scenario where it makes sense for the database to be on the same disk as the application code. SQLite’s maintainers consider it to be among themost replicated pieces of software in the world.

How to install SQLite

Binaries for SQLite can be installed at theSQLite Downloadpage. This page has versions of SQLite for Windows, Mac OS X, andLinux. The last number in each file name is the current SQLite version. Our video walkthrough uses the version number3200100. You should download whichever version is listed on the SQLite Download page, and replace3200100in the instructions below with the version number you downloaded. For example, if the name of the file you download issqlite-tools-win-x64-3490100.zip, you would change3200100in each command to3490100.

Installing SQLite on Windows

For Windows machines:

  • Download thesqlite-tools-win-x64-3490100.zipfile and unzip it.
  • From yourgit-bash terminal, open the directory of the unzipped folder withcd ~/Downloads/sqlite-tools-win-x64-3490100.zip/sqlite-tools-win-x64-3490100.zip/. 3.Try running sqlite with the commandwinpty ./sqlite3.exe. If that command opens asqlite>prompt, congratulations! You’ve installed SQLite.

We want to be able to access this command quickly from elsewhere, so we’re going to create an alias to the command. Exit thesqlite>prompt by typing inCtrl+C, and in the same git-bash terminal without changing folders, run these commands:

echo "alias sqlite3=\"winpty ${PWD}/sqlite3.exe\"" >> ~/.bashrc

and

source ~/.bashrc

The first command will create the aliassqlite3that you can use to open a database. The second command will refresh your terminal so that you can start using this command. Try typing in the commandsqlite3 newdb.sqlite. If you’re presented with asqlite>prompt, you’ve successfully created thesqlite3command for your terminal. EnterCtrl+Cto quit. You can also exit by typing.exitin the prompt and pressingEnter.

Video Tutorial:Setting Up SQLite Locally (Windows)

Installing SQLite on Mac

For Macs, use the Mac OS X (x86) sqlite-tools package:

  • Install it, and unzip it.
  • In your terminal, navigate to the directory of the unzipped folder usingcd.
  • Run the commandmv sqlite3 /usr/local/bin/. This will add the commandsqlite3to your terminal path, allowing you to use the command from anywhere.
  • Try typingsqlite3 newdb.sqlite. If you’re presented with asqlite>prompt, you’ve installed SQLite! Entercontrol+dto quit. You can also exit by typing.exitin the prompt and pressingreturn.

Video Tutorial:Setting Up SQLite Locally (Mac)

Installing SQLite on Linux

In Ubuntu or similar distributions:

  • Open your terminal and runsudo apt-get install sqlite3. Otherwise, use your distribution’s package managers.
  • Try typing in the commandsqlite3 newdb.sqlite. If you’re presented with asqlite>prompt, you’ve successfully created thesqlite3command for your terminal. You can exit by typing.exitin the prompt and pressingenter.

Conclusion

You’ve installed database software and opened a connection to a database. Now you have the full power of SQL at your fingertips. You’ll be able to manage all the data for any application you can dream of writing.

To explore how to use SQLite in real-world applications, check outLearn Node-SQLite. This course teaches you how to integrate SQLite withJavaScriptusing the node-sqlite3 package, making it a great next step after learning SQLite basics.

'The Codecademy Team, composed of experienced educators and tech experts, is dedicated to making tech skills accessible to all. We empower learners worldwide with expert-reviewed content that develops and enhances the technical skills needed to advance and succeed in their careers.'

30% Free Preview Reached · Unlock Remaining 70%

Complete Payment to Unlock Full Guide & Source Code

You are viewing the 30% preview. Join TopCourseAI Pro to unlock the remaining 70% of this article, unblur all code snippets, and gain full access to all 412 technical projects and guides.

✓ Full Access to All 160+ Projects
✓ Instant Blur Removal Everywhere
✓ Production Source Code & Blueprints
✓ All Future Deep Dives Included
Instant Unhindered Activation ·
End of Preview · Unlock Complete Blueprint & Source Code

Ready to access the complete step-by-step tutorial?

Gain full unhindered access to all 412 technical projects and guides, unblur all source code snippets, and download runnable scripts.

Production AI Blueprints

Ready to build production-grade AI systems?

Enjoyed this guide? Continue exploring our library of 166+ production blueprints, multi-agent swarms, and autonomous agent systems with 100% unblurred, executable source code.