- [Instructor] Let's now use MySQL
to implement our maxcoin sample.
Other than Redis and MongoDB,
relational databases like MySQL
rely on static table structures so-called 'schemas'
to have to be defined directly inside the database.
For larger systems, creating the database design
is actually a science of its own.
The maxcoin application though is very simple.
So let's create the schema for it now.
So I'm in MySQL workbench and I have the Schemas tab open
and there I now right click and click on 'create schema'.
And for the schema name, I will now just insert 'maxcoin'.
We can leave the default for the character set
and the collation which is used for sorting of strings.
Next, I will click on 'apply'.
And there my SQL workbench shows me the....
Actually comments that it will execute on the database
and it creates schema command for the database, 'maxcoin'.
Next I click apply and then I can close this.
Now I have a database 'maxcoin', we see it here
and of course I need a table now,
where our values are stored.
So now I click on 'tables', then I right click.
And then I click 'create table'.
And then now I can define the table
and everything starts with the table name
and I call it 'coinvalues'.
And then we can already define the fields
or the columns in this table.
So the first column I will create is called 'ID'.
And this field should be the primary key
and it's already automatically selected here.
So the primary key uniquely identifies one record
in the database and I also check here, this AI column.
If I scroll over that, it should show that
it marks the column is auto increment.
For that MySQL will now just automatically
use an auto-incremented number for this ID.
Next I need a field for the date so I go to the next line
and here I call this column 'valuedate'.
I cannot use the name 'Date' here
because this is reserved in MySQL.
And for the data type I now select 'date'.
I have to type that in.
And then I also of course need a column for my value
and I call this 'coinvalue'.
And this should be a decimal field.
And I can define the size of this now.
So, let's say it's '10,2', so this means
that it will have 2 digits after the comma.
I also want to define one index
because later we want to sort by coin value.
So I click on 'coinvalue'
and down there you see this tab 'indexes', I click on that.
And here I now click on the next row below primary.
And I call this index 'valueindex'.
And this value index should now be for the coin value
And there I also select descending for the order
because this is exactly how we will later then select
the maximum coin value as we did for the other databases.
So it makes sense to just store the index
in this way already and then I can already hit 'apply'.
And then you see that
we have this 'create table statement' here
for the coin values table.
It creates columns for 'ID', 'valuedate' and 'coinvalue'.
It defines a primary key and then it also sets
this index for the coin value.
So this should be fine and I can now hit 'apply'.
And now we have a new table 'coinvalues'.
So this is the preparation on the database
that we needed to implement our maxcoin example with MySQL.
And we will now go ahead
and implement the actual code for this.