My first encounter with Databases

Image provided by Markus Spiske from Unsplash - https://unsplash.com/photos/xekxE_VR0Ec

Image provided by Markus Spiske from Unsplash - https://unsplash.com/photos/xekxE_VR0Ec

We produce a lot of data. And as a information driven generation, we revel in it, look at it, visualize it, take it apart, request it, store it, and share it.

When I first encountered databases I imagined noisy boxes with blinking lights stored somewhere in the cellar of a secret society (which isn’t that incorrect). I imagined that I would have to input hundred lines of code and hunt encrypted information in the secret language between the lines.

And yet, data in a databases is stored in tables. A database is a collection of tables with different types of datasets.

A table like this, multiple times with different information:

(no, these numbers aren’t real)

(no, these numbers aren’t real)

 
A database is a great alternative to a publicly shared Excel file, which after some time, is likely to become curropted

While files like Excel are designed for users to view information all at once, databases are designed for you to pick and sort chunks of information from a massive pool of information.

A table has rows and columns. Each cell in your row+column combination contains a datatype.

Dataset Sabina Hadiza Schmitz

I learned that SQLite is great way to get started on Databases. The benefits are having them stored on your computer locally. This is the code I used to start my own little Database:

The hashtags are comments within my file.

#I am importing SQLite
import sqlite3
#I’m establishing a connection(conn) and calling the database “learning.db”
conn = sqlite3.connect('learning.db')
#C is the cursor. Like a mouse cursor that you can tell how to move in your database
c = conn.cursor()

Database Sabina Hadiza Schmitz

When I ran the code, nothing happened initially. BUT when looking into my project source file (The place where I have my IDE aka code document and launcher stored) I found a .db file. I just created a database! It can now be filled with tables and data.

# I am now creating a table and defining the dataset type for each of the coloumns.
#I am giving C the instructions to execute this
def create_table():
    c.execute('''CREATE TABLE example 
    (Language VARCHAR, Version REAL, Skill TEXT)''');
create_table()
# I am manually entering data into the database and commiting it into the system
def enter_data():
    c.execute("INSERT INTO example VALUES ('Python', 2.7, 'Beginner')")
    c.execute("INSERT INTO example VALUES ('Python', 3.3, 'Intermediate')")
    c.execute("INSERT INTO example VALUES ('Python', 3.4, 'Expert')")
    conn.commit()


My database now has a bit of data stored in it.

CodeSabina Hadiza Schmitz