Creating MySQL Table to store Tick Data

It is better to create a MySQL table beforehand, to store the incoming tick data.

I will name the table ‘sample’.

This was successful. Now we have a table named ‘ticks’.

Next, let’s try to add Instrument Token.

Now, let’s add the Last Price.

You must be thinking, why I am adding all these things one by one. Actually, if you try to add everything in one go, you wouldn’t understand where you went wrong when the MySQL servers throws an error. That’s why it is wiser to move ahead one by one.

But now that we have tested the data types, we can add in bulk.

Now, let’s get into the tricky part. That is adding another column by the name ‘time’ and we will specify it’s data type.

That’s it, it’s simple, you don’t have to do anything else. Every time you update a record, the time will get updated automatically.

To check this, let’s run an sql query.

 

Here, we inserted last_traded_quantity and last_price.

Now, let’s try to retireve the data and see what we get.

Upon running the above query we get the following result.

You will see that the time value is updated automatically.

Full Code

If you want to create this table at one go, you would try the code below.

However, don’t forget to select the database before typing. This happened with me.