SQL 101: Interacting with the Memories in your Pensieve

Leanne Cabey
Dec 27, 2018 · 4 min read

If you’ve read my previous post, Magic Spells and Object Oriented Programming, you know that there is actually a lot of code running behind the scenes for every spell you cast. But what you may not have known is that there is also a lot of code required to interact with the memories in a pensieve.

SQL, or Structured Query Language, can be used to add, edit, read, and remove memories from your pensieve. Muggles use SQL to interact with a database, which is very similar to a pensieve.

Pensieves, like databases, are organized into various tables of related information. Horace Slughorn’s pensieve/database, for example, may have tables such as fav_self_transfiguration_memories, top_potions_successes, convos_with_dark_wizards, and famous_ppl_i_know. Here’s a sneak peak of his convos_with_dark_wizards table:

Reading from a Pensieve/Database

So you’re Horace Slughorn, and Dumbledore just approached you about a record in your convos_with_dark_wizards table from 1942 that he wants to see. He says it was a conversation with Tom Riddle that may have set him on his path to becoming Voldemort. Dumbledore and his dramatics 🙄. Before you let him access it, though, you want to take a look at it yourself. To access all of the records in that particular table, you can run the following SQL query:

The * character means all the columns in the table. So the above query reads very much like English: select everything from the convos_with_dark_wizards table. But this doesn’t really help you find the particular record you’re looking for. You’re going to need to add a WHERE clause to your query to make it a little more specific.

Now that you’ve successfully pulled the appropriate record from your database, you take a look at the full_transcript field.

Uh oh. Dumbledore may have had a point…

Updating Records in a Pensieve/Database

You now realize that before you hand this record over to Dumbledore, you’re going to need to make some changes. You can update a record in your pensieve/database using the following SQL syntax:

We can see from the output of our previous SELECT statement that the id of the record we’re dealing with is 2. So we can manipulate that particular record via an UPDATE statement by including the WHERE id = 2 clause. Now when you look at that record, you’ll see the updated full_transcript value:

Perfect. Dumbledore will never know the difference.

Removing Records from a Pensieve/Database

Now you’ve decided that you had better go ahead and remove all other records that connect you with Voldemort. Obviously he is incredibly famous, but even Horace Slughorn has standards. You can accomplish this with the following SQL query:

This will delete all records from the convos_with_dark_wizards table where the convo_with value is Tom Riddle, excluding the record Dumbledore has asked to see (the != means not equal to).

Adding Records to a Pensieve/Database

While you’re at it, you might as well paint yourself in the best possible light by adding in some new records to your convos_with_dark_wizards table. You need to show Dumbledore that you always prioritized being a responsible professor and mentor. You can insert new records into your database using the following SQL syntax:

You’ll notice that we didn’t need to include the id field with the field names or the values to be inserted. This is because id is an auto-incremented primary key, which means that the pensieve/database will auto-magically assign an id value to all new records that are created.

Now your convos_with_dark_wizards table looks like this:

Success. Thanks to some very basic SQL, you can go down in history as having contributed nothing to Voldemort’s rise to power!

Data Driven Investor

from confusion to clarity, not insanity

Leanne Cabey

Written by

Full-Stack Software Developer

Data Driven Investor

from confusion to clarity, not insanity

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade