Skip to content

Python Sqlite Tutorial – with Examples

Python Tutorials

Digital space is growing to enormous sizes bringing enormous digital opportunities with it. At the center of these opportunities sits the term data. In this 2019 article World Economic Forum estimated 2020 digital space size to reach 44 zettabytes. A number that equals 44 billion terabytes (or 44 trillion gigabytes). In the same Weforum article it’s stated:

If this number is correct, it will mean there are 40 times more bytes than there are stars in the observable universe.

And this Nasdaq article states 95% of all shopping is expected to take place by 2040. In this tutorial series we focused on a very useful data management skill: relational database management systems and SQL techniques combined with Python programming language.

SQL Introduction

SQL stands for Standard Query Language and was founded by an IBM scientist named Edgar Codd in 1970. It is pronounced as Sequel or S.Q.L and there are funny debates about it every now and then. Watch Bill Gates tackle the issue by hilariously calling it both ways: Bill Gates SQL Server Commercial.

Big data management is the top skill that Enterprises need and students lack according to this Anaconda State of Data Science 2020 survey which can be acquired by filling the form here.

You can see this recent Kaggle 2020 Data Science survey also, to see the emphasize on SQL based database solutions and their use in Data Science industry.

by following these courses you will learn a great deal about database and sql. Furthermore you will learn how to comfortably use the most modern open source database tools and integrate databases to your projects.

It’s hard to imagine programming or computers without databases. As we approach mass adaptation of the next chapters of internet age such as blockchain technology, cloud solutions, Starlink, machine learning and AI revolution, learning this very useful and fundamental technology will help you bridge the gaps between you and advanced tech.

The good news is most intermediate Python programmers can pick up the knowledge in these SQL tutorials in a matter of 1-day to a few days.

1- MySQL and SQLite

MySQL on the other hand is a relational database management system (RDBMS) that’s used to contain and query data. It made SQL popular world-wide and has been adapted by many successful companies and their services.

MySQL was founded by a Swedish tech startup (and its programmers Michael Widenius, David Axmark and Allan Larsson) named AB in back in 1995.

Fun fact: Interestingly MySQL’s name comes from Michael Widenius’ daughter’s Nordic name My and not the English word my.

In early 2000s MySQL saw increasing success and integration by tech savvy companies. In fact, WordPress, the leading open source website content management technology in 2021, was founded by Matt Mullenweg and Mike Little in 2003 using MySQL.

In 2008 Sun Microsystems bought MySQL (and AB with it) for $1 billion and in 2009 Oracle bought Sun Microsystems for $5.6 billion (Oracle Sun Microsystems deal).

In 2010 Michael Widenius forked a MySQL under GPL-Only open source license and named it MariaDB which ensured the public availability of MySQL RDBMS under copy-left open source licensing.

MySQL or its derivatives are used by tech giants as well as tiny startups today. Netflix, Pinterest, Twitter, Udemy, Youtube, Nasa, Uber, Tesla, AirBNB, Virgin, CERN, JP Morgan, BofA, Github just to name a few [detailed list here]. In fact, there are so many companies that use SQL technology we’d probably need a database to list them all.

SQLite is a library that can be used to works with databases and it works really well with Python. In this tutorial series we will work in tandem between Python, MySQL database systems and Sqlite.

2- SQLite Tutorial Series

You will learn how to:

  • create databases
  • query data from databases
  • manage database tables
  • use sqlite3 library
  • enter data into database tables
  • more advanced techniques to query data
  • cloud database implementations and how to use them with Python

MySQL is a very standardized system which works across pretty much all platforms that exist. This is also one of the ingredients in MySQL’s success recipe.

This means you will also be able to work with other open-source and proprietary SQL solutions without any extra effort or little extra effort. Names of some of these 

SQL Solutions:

  • MySQL
  • PostgreSQL
  • MariaDB
  • SQLite
  • Apache OpenOffice Base
  • Microsoft SQL Server
  • Oracle Database

SQL Cloud Solutions:

  • Google Cloud SQL
  • Amazon RDS
  • Postgre SQL cloud
  • Oracle DB cloud
  • Microsoft Azure
  • IBM DB cloud
  • Kaggle Cloud

3- Why Learn SQL?

Learning SQL is sort of a no brainer.

  • you can learn it fast and become proficient in less than a week
  • it can be a life changing experience
  • it caters the needs of professionals and entrepreneurs alike.
  • it can support small businesses to the biggest tech corporations that exist
  • it compliments Python skills very well
  •  it polishes up your resume big time
  • it opens new horizons for entrepreneurial projects
  • besides you can do blazing fast in-place visualizations
  • you can also implement a cloud database solution for further flexibility, security and robustness (more on this below)

Can you see SQL’s leverage? With one little effort you untap a whole new world of opportunities from corporate recruitment to entrepreneurship, from amateur projects to world-class innovation and precision.

SQL is the epitome of working smart and not just working hard. 

You will finally learn relational database management.

4- Surge of Data

They say data is the new oil, and there is a rush indeed. This metaphor makes lots of sense because like oil, data needs to be processed, like oil data needs to be contained and preserved and like oil data enables technology.

Most people tend to focus on processing part of data science (and all the other disciplines that require working with data) but you will be missing so much if you don’t know how to contain, manage and query data in most efficient ways. 

SQL or databases in general do exactly that. They contain data. And they do it really well. SQL database systems are blazing fast and they work flawlessly and efficiently with big data across many platforms.

5- Recruitment Options

Becoming aware of SQL’s benefits most companies started putting SQL on top of their desired recruitment skill lists.

Data Science is listed as 2nd best job in America in 2021 with median base yearly gross salary of $113K according to this Glassdoor Best Jobs List

75% of data scientist jobs posted on Indeed look for candidates with SQL skills according to this great SQL demand analysis article by DataQuest.io and I bet majority of those remaining 25% are looking to give on-site SQL education to their candidates.

Machine Learning & AI

Another hot topic is Machine Learning and AI. As AI technologies mature, data becomes more and more relevant. Seeing the AI revolution take place and the new benefits it offers, companies, entrepreneurs, academia and scientists will continue focusing on data at an increasing speed.

Artificial Intelligence industry is expected to reach 2131231231 trillion dollars in 2025.

6- So, Should I Really Learn SQL?

Short answer: Absolutely. Yes! 

Long answer: Long answer is an elaboration of ROI for learning SQL and its synergies with Python. Think of your time and effort as resources you are investing and opportunities, skills and potential outcomes as your return from learning SQL, MySQL and SQLite.

If you are a Python programmer (or becoming one) or data scientist or just a scientist even, you really have no excuse not to learn SQL (and integrate it to your Python applications). SQL is kind of a mini language so it’s relatively easy to learn. If you are really determined you could learn it in one or two days. And for the opportunities it enables, any reputable figure in business, science or tech world will tell you it’s a no-brainer to have a good command of SQL query language.

Even if you have a job (or planning to get one) that is not directly dealing with the database, knowing SQL will make you more independent, more confident and more creative. Let’s say you’re working in one of these professions: trader at a bank, medical researcher, government official responsible for city planning or a student with any major, in all of these cases you can benefit from being able to work with databases and handling data like a champ.

Even when you have an assistant or analyst that can handle your database operations, learning SQL will make you more independent and it will also help you actually understand where the data is coming from, how it’s structured and what insights can be extracted from it.

On the other side if you are more of an entrepreneur type person, SQL really compliments your other tech and programming skills and enables you to actually create world-class projects.

55% of all developers reported (and 57% of professional developers) reported using SQL in this StackOverflow 2020 survey.

MySQL was the top database solution used by programmers by 56% while SQLite had a 32% share.

Now that we’ve established our case and hopefully strong motivation is in place, without further ado let’s master MySQL and SQLite with Python.

7- SQL Learning Gameplan (Or Syllabus)

Or study plan! Pick whatever you like, here is a route you can follow to master SQL with Python in a short amount of time and become a proficient SQL developer.

By following this study plan you can learn SQL and use it proficiently for your projects or ace your job interview or school studies.

  1. Database Tables and Getting Familiar –> DB Browser for SQLite (Open Source)
  2. Manual Operations –> DB Browser for SQLite
  3. Starting Querying –> DB Browser for SQLite
  4. Mastering Queries –> DB Browser
  5. Exploring SQLite –> Python and SQLite
  6. More Advanced Operations –> Python and SQLite
  7. Specialized SQL Operations –> Python and SQLite
  8. Experimenting with Cloud Solutions –> Python, SQLite and GoogleCloud (Optional)

This is the recommended path to SQL excellence, feel free to mix and match and choose from the tutorials we provided above.

As always, practice makes perfect and starting with the basics will help you have fun, remain confident and maintain a well-balanced dopamine profile.

Actionable Outcomes:

By the end of these tutorials you will have:

  • Learned how to use SQLite and DB Browser for SQLite
  • Created a MySQL table (including with Python)
  • Inserted values into your database (including with Python)
  • Learned how to Query from the database (including with Python)
  • Learned how to Query from the database and uncover meaningful insights 
  • Learned how to deal with little bugs and nuances that might appear

8- Python SQLite Examples

In Python specific parts of this tutorial series you can learn how to create database connections and create database cursors to work on databases. You can also learn how to make database management and databases querying operations such as:

  1. Creating database tables with Python
  2. Managing database columns with Python
  3. Inserting rows into SQLite databases
  4. Querying databases with specific conditions
Later on you can also check out our Python magic tutorial specifically for SQL based on Ipython-sql library. In this tutorial we will focus on using coding cells and lines to directly run sql scripts from a Python IDE such as Spyder or from Jupyter Notebook.
Life after SQL

9- Specialized SQL Tutorials

We are also working on specialized SQLite examples with Python. These tutorials will cover domain-specific applications such as:

  • Time Series with SQL
  • Multiple Tables with SQL
  • Querying SEO data

10- Database Visualization

Everything is more beautiful and intuitive with visualization. That’s how we’ve evolved and what our sensory cortex seeks. So, we have also included some very practical database visualization features in this series.

SQLite database visualization example

11- Career Prospects

Based on our research on several recruitment sites such as Indeed, Glassdoor and ZipRecruiter these are the common SQL specific job titles we have come across:

  • Statistical Programmer (SAS, SAP, Database, Macro, SQL, Graph)
  • SQL Developer
  • SQL Database Developer
  • SQL Analyst
  • Data Analyst
  • Database Specialist
  • Database Manager
  • Database Engineer
  • SQL Server Database Administrator
  • Database Administrator, (Oracle Manager, SQL Manager)

Although one can specialize in SQL and databases and completely focus on this domain, SQL is also a complimentary skill in many IT job titles. This list would be very extensive but here is a couple of examples:

  • Data Scientist
  • Python Developer

In most programming and IT positions SQL skills are known to have an instant impact and boost income from anywhere between 10% up to 50%.

There is no clear rule about salaries and income one can make but while more general titles like Python Developer, JavaScript Developer or Data Scientist seem to make annual gross salaries between $100K to $150K, SQL specific entry level jobs such as Database Analyst or Database Specialist are expected to earn sub-$100K incomes, anywhere between $60K to $70K gross yearly.

On the other hand database occupations with more advanced and technical responsibilities such as Database Developer and Database Engineer can still expect to earn higher between $90K and $130K per year. These jobs will have daily tasks that go way beyond simple data entry or database querying and they will engage in complicated database relations, high speed database performance, database engineering and tuning, real-world database implementations for applications, games and websites or more specific systems such as stock exchanges, cryptocurrency exchanges, government data or defense systems.

That being said, kindly realize that one can employ technology in any kind of work and that includes SQL and database solutions. We are discovering more ways to harvest technology in our lives and there is no reason why a nurse, dentist, farmer, school teacher or a pharmacist shouldn’t implement database solutions and use SQL themselves.

Addition to that, entrepreneurs and startup founders as well as small business owners can immensely benefit from understanding and learning solutions that include database operations, SQL, MySQL and SQLite.

12- Resources

In this database tutorial series with SQL, Python and SQLite we have included quite rich learning resources with examples. We hope these will be helpful for learning database applications in addition to Python for our audience.

Additionally you can refer to these resources for scripting with SQL:

  • Your local environment
    • Python
    • SQLite
    • Pandas
    • DB Browser for SQLite
  • Kaggle
  • Google Cloud (or other cloud services)
  • Other cloud services such as IBM DB2, Amazon RDS and Oracle.

It’s common to start with SQLite and work your way up to cloud and enterprise solutions or sometimes SQLite might be all you need.

Summary

In this Python Tutorial we have learned a lot about Relational Databases and how to use and manage them with SQL. We also learned how to manage and query SQL databases with SQLite library in Python.

We discussed the benefits of SQL and its future look as a skill for professionals, amateurs,  scientists, students, job seekers, programmers, data scientists, entrepreneurs, basically all kinds of people.

We also utilized DB Browser for SQLite for operations with user interface and we explored Google Cloud solutions for more serious and Enterprise like solutions.

We wish you fruitful and innovative outcomes with your SQL oriented skills and experiments.

If you can, don’t forget to support Holy Python every now and then so that we can keep serving you with top quality programming content.

Also, now that you can SQL databases at the tip of your fingers, you should totally dive  (or re-dive) into machine learning with class. Another topic that goes really well with Python.