Using microseconds in the DATETIME columns
There was a time when measuring dates and times accurately to within a single second were as precise as we needed it to be. However, those days are gone. Users expect their apps to have response times of well under a second, and so our databases must be able to track those times as well.
How to do it...
Launch the
mysql
command-line client application and connect it to our MariaDB server.Create a test database if it doesn't already exist and switch to it using the following command:
CREATE DATABASE IF NOT EXISTS test; USE test;
Create a simple two-column table named
times
using the following command:CREATE TABLE times ( id int NOT NULL AUTO_INCREMENT, dt datetime(6), PRIMARY KEY (id) );
Run the following
INSERT
statements at least four times and add some sample data to our table using the following command:INSERT INTO times (dt) VALUES (NOW()), (NOW(6));
Select all of the data from our table with the following
SELECT
command:SELECT * FROM...