All right.
So this will be a quick video where we just implement the two tables we need.
They're both very simple.
So tag's it's just an idea and a tag name photo tags is a photo ID and a tag ID.
OK.
So here I am in cloud 9.
I will start with our tags table create table tags and all we need is an ID which is an integer auto
increment primary key and then we'll also have our tag name which is just a VAR char 255 and we want
to make it unique.
We don't want to have oh my gosh I can spell unique.
You don't want to have any duplicates in there.
And then after that you know it would be nice to edit create it.
Like I said so we could store it the first time a tag was used or created and that's it.
So that's our tags table.
This table here.
Now we've got to worry about photo tags.
So we'll do our create table photo tags or tagging.
Which is also nice I guess.
Well it is nice but also works.
We don't need an ID although we need is a photo ID and then the tag ID.
And those are both going to be integer not know
we go.
And then on top of that we need to add our foreign key constraints foreign key photo ID is referencing
the photos table ID field duplicate that tag ID for his referencing tags table ID field.
We also want to make sure that a user cant tag the same photo with the same hash tag multiple times.
And thats an easy fix.
We just do our same primary key with two items.
Photo ID and tag ID and that just ensures that we can have multiple instances of the same photo tags.
All right don't so my colon looks like I'm missing this comma here and there we go.
Now if we try that
and we look at our tables.
There we go we've got comments for all those likes photo tags photos tags and users.
And that's it for our schema.
We're done.
So in the next section if you'd like to tap out now.
Move on to the next section we're going to give you a massive file with a bunch of data that I created
took way too long to do that.
We'll be able to do some exercises with and get some practice working with a bunch of tables.
But if you want to see me just insert a couple of tags and photo tags to do that now.
So if you're still here going to do that.
Start with inserting a couple of tags and all we have is tag name
and just to verify that you go back up to our tags it's just a tag name that we're inserting.
So let's say I'm inserting the string you know adorable
and we get to more say cute.
And one more would be I don't know.
Sun rise.
OK.
So that will answer our tags.
Can you make sure that that works.
Select star from tags.
There we go.
We've got three tags Now we associate them with photos.
And so you've got three photos.
You know it doesn't matter what they are but they have an idea of 1 2 and 3.
So if you want to do an insert into spell answered correctly photo tags will start by taking the photo
ID and then the tag ID OK values and let's say the first photo is tagged with adorable.
And the first photo was also tagged with cute because it has an idea of two and then will say the second
photo is tagged with.
I don't know sunrise.
And then the third photo is also tagged with cute like that.
OK.
So you can rerun this.
Let's do this.
Let's start from photo tags.
There we go.
Looks good.
Now the true test is can we still insert something that shouldn't work like a duplicate.
We already have one common one so entered into photo tags.
Photo ID comma tag ID values one comma one and we get duplicate entry.
So that's good.
Works perfectly.
But as you can see no other order works fine to come in three or three common two are not the same thing
at all.
This is saying the second tag.
This is saying the second photo should have the third tag.
This is saying third photo should have the second tag.
Quite a mouthful.
All right.
So we're done here.
Next up we're actually going to play around with data.
Like I said I'm going to give you a giant file.
Hopefully it's fun.
And if it's not.
Well we're basically in the course so just hang in there.