Okay.
We have done a lot of groundwork talking about tables.
Let's actually see the syntax to create a new table.
So to create a new table, we specify a table name, but we also specify all the column names and their
corresponding data types.
So we run create table that's always create table, and then the name of our table and then parentheses
and then column name data type.
So that could look like this.
Create table cats.
Every cat has a name column that is text.
It's a var char 100 length maximum and age is an integer.
Those are the only two types we've covered.
So we're going to use those two types.
Now, as far as formatting, it doesn't have to go on separate lines like I have it here.
It's just a nightmare to show you on slides if it's one massive line of text.
But remember that my SQL doesn't care about new lines or anything.
Well, it cares about the characters we type and it cares about spaces between things, but it doesn't
care if I hit return and I have new lines here, and that can make it a lot easier to enter your information.
So we also need to separate our different columns that we are declaring with commas.
And then of course, we terminate the whole statement with a semicolon.
So let me show it first in the command line or in the MySQL client here.
What database am I in t shop?
So let's show databases.
Let's switch to let's make a new database.
How about that create database.
Let's call this one pet shop.
Okay.
And then use it.
Okay.
And now what I'm going to do is create my first table.
Let's just do what we have on the slides here, or maybe slightly tweak it, but we'll create a table
for cats.
It's a pet shop, which I feel bad.
It should be a shelter, really, but I don't want to change it now.
So create table once again.
That doesn't have to be capitalized, but it helps it stand out.
I'm going to call this cat and then open my parentheses here or on the next line.
It really doesn't matter.
I'll just do it right there.
And then my first row and my first column rather, is going to be called Name, which is a var char.
And do we need a limit of 100 characters?
Maybe a cat's name has to be 50 characters or smaller.
Sure.
And then a comma.
And then I'll just hit enter again.
And on this line I will do age.
It's an int, so let's just leave it at that and then close my parentheses and add my semicolon.
And it looks like it worked.
How do we know?
Well, there's a couple of ways in this video.
The one that I'll show you is if we just go over to one of our tools like DB Gates or my SQL workbench,
if I refresh the connection, we see Pet Shop and within Pet shop we should see.
Hello.
There we go.
The cat's table exists.
Same thing over here.
If I refresh my view here, we see there's a pet shop database.
It has a table called Cats and there it is.
That's cats.
Now, that's kind of a janky way of verifying that it worked.
But in the next video, I'll show you some other commands that we can run from the command line.
Now, we can also make cats or any other table.
Let's make a dog's table from within one of our SQL graphical interfaces.
So it's the same process.
You make sure you're using the correct database.
And then let's close this.
I will double click on the pet shop, click my plus sign and write my script that will do something
like create table dogs.
Let's just do dogs this time.
And it's going to be the same sort of pattern.
I'll indent if that makes it a little nicer to look at.
So name will be once again a var char.
Let's do 50 characters age.
Let's do breed for dogs.
Breed will be a our car of 50 characters as well and age is an integer.
You can write it out like that or just do int and then I have my semicolon.
Okay.
And then if I click execute here.
That should have inserted a new table for me into pet shop.
And that table, if I refresh down here, is called Dogs.
We see it over there.
Same thing in workbench, my SQL workbench.
It's really hard to see over here with that tiny little text, but there is now a dogs table.
Okay, so that's the basic syntax.
That pattern you'll see all over the place.
You use it all the time, every time you need to make a table, create table the name of the table.
You want to come up with a name that makes sense, of course, And usually it's plural sized, but there's
no rule that it has to be.
And then parentheses.
And then our column names with their corresponding data types, separate them by a space and then separate
each column using a comma, terminate it with a semicolon.
So we'll get a lot of practice creating tables.
But that's the basics.