Today we focused on database design, specifically exploring the concepts that drive relational databases.
What's a relational database?
It's a collection of tables storing different data pieces that refer to one another to form a complete picture of something. By referencing other tables, we can stick to one value per field design principles while adding organized complexity to our entries.
What?
Today, we used a film database as an example. This database had tables for films, actors, and directors.
You can't just include a list of every actor in a movie in the films table, so you need a way to keep track of each film's cast. This is where a one-to-many join table comes into play.
You can create a table where each record is a film ID, an actor's ID, and the name of the role they played. A query to this table can then return each actor ID matched with a single film's ID and provide a comprehensive list of every actor in that film.
This way, you can keep track of the dozens of actors that make up a film's cast without bogging down every table.
Conclusion
This form of database design applies to SQL, it's been a while since I've studied SQL, so it was nice to get a refresher.
Top comments (0)