My first encounter with Databases
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:
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.
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
#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()
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
c.execute('''CREATE TABLE example
(Language VARCHAR, Version REAL, Skill TEXT)''');
# I am manually entering data into the database and commiting it into the system
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')")
My database now has a bit of data stored in it.