Now that we’ve created our users and photos tables and connected them using a foreign key, it’s time to actually use that relationship. Enough theory — let’s write s
MSMuhammad SufiyanSoftware Engineer · 6d ago
Backend Engineering HubT-
Now that we’ve created our users and photos tables and connected them using a foreign key, it’s time to actually use that relationship.
Enough theory — let’s write some real SQL queries and see how this relationship helps us fetch meaningful data.
Adding More Photos to the Database
Right now, our database only has one photo. That’s not very exciting 😄
So let’s add a few more.
Remember:
Each row in the photos table represents one photo
Each photo belongs to one user
The user_id column tells us which user owns the photo
Inserting Multiple Photos at Once
We can insert multiple rows in a single query by adding multiple sets of parentheses.