All righty.
Let's go through the solution.
Spring cleaning.
We're doing our closet inventory, and the first step was to create a brand new database called Shirts
DB.
So if we hop over to cloud nine, if we just check what database we're using, remember, we can do
select database.
We're using cat app.
So we're going to make a new database, create database, and we wanted to call it shirts, underscore
DB semicolon.
Now if we do show databases, you can see we have shared SDB down at the bottom.
All right.
So the next step, we need to use shirts.
DB Just like that.
And now if we run that same select database line, we're currently using short SDB.
So now this is probably the longest thing you'll have to type.
We need to create a new table.
We'll call it shirts, and it needs to have these five columns, shirt ID, which can not be null and
as a primary key, which means that we'll have it auto increment as well article which should be var
char and let's just for simplicity say all of these have 100 character limit color var char 100 shirt
size.
Yes, we could have kept it short, but maybe you might have a shirt size that's small spelled spelled
out the full word rather than just a letter s.
So we're not going to limit that either for now.
And then last worn is an int.
So let's try it.
We'll do a create table shirts and I'm going to do this on a new line here.
And the first thing that we have, let's start with shirt ID, which should be an integer, not null.
Auto increment.
Next, we're going to move on to article, which is a var cha 100.
And then after that we have color, which is also far 100.
Then we have shirt size, which is also var CHA 100.
And finally, we have last worn, which is an int.
Just like that.
Then we'll close our parentheses and then we'll add our semicolon.
And I forgot something which I did not do on purpose.
But if we look at the message says incorrect table definition, there can be only one auto column and
it must be defined as a key.
And so I'm missing the primary key definition at the end, which this is actually a helpful error.
Oftentimes these error messages aren't that useful, but this one tells us exactly what we did wrong.
So I'm going to recall that line.
And then at the end I'm going to add comma primary key.
And then our primary key is shirt ID, just like that.
Now, if I hit enter and you look at that, I left off the last parentheses again.
So we have another error.
So now if we hit enter here, it worked.
If you'd like to see a nice cleaned up version of what this actually looks like here I have it here.
So create table shirts, shirt ID, and not an old auto increment article.
Cha cha cha cha cha cha shirt sized cha cha last worn int primary key shirt ID and the semicolon and
the correct parentheses closing it out.
And that should do it.
All right.
And if we wanted to double check that things worked, we can do our describe shirts and you can see
we have what we expect.
So the next thing is to get all of this data in our database.
So I gave it to you as this comma separated list where things are all in the same format, where we
have parentheses for one shirt, and then inside of that we have article first and then color and then
size and then last worn.
So we can insert using that format.
So we'll do an insert into shirts and we have to specify we're doing article first, then we're doing
color, then we're doing shirt size, and then finally we're doing last worn and then we need our values.
And I'm just going to hit enter for now and I'm going to paste that giant list and we need a semicolon
at the end and we hit enter.
Good.
No mistakes this time says records.
Eight, eight rows affected.
Okay so if we want to just to double check can do our select star from shirts and we get the data in
there that we should have.
And then the last thing we need to do is to add a new shirt.
So manually, one shirt, rather than bulk inserting, it should be a purple polo shirt.
That's medium that was last worn 50 days ago.
So I didn't specify what order you needed to insert into, so I don't really care.
But we'll do insert into shirts and we'll do color because that's how I specified here color, then
article, then size and then last worn.
So color article shirt size last worn like that values.
And it's purple.
Polo shirt.
Comma, medium, comma, 50.
Just like that.
Okay.
And if we do select star, we should see that new polo shirt down there.
It's Purple Medium.
50 days ago, we wore it.
All right, so we've now wrapped up the create part of crud.
We saw how to create the database we inserted, created a new table.
We inserted data into the table.
Now we're moving on to reading.