Book Image

MariaDB Cookbook

By : Daniel Bartholomew
Book Image

MariaDB Cookbook

By: Daniel Bartholomew

Overview of this book

Table of Contents (20 chapters)
MariaDB Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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...

  1. Launch the mysql command-line client application and connect it to our MariaDB server.

  2. 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;
    
  3. 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)
    );
    
  4. 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));
    
  5. Select all of the data from our table with the following SELECT command:

    SELECT * FROM...