MySQL DATETIME Default Value Guide

In MySQL, you can set a default value for a DATETIME column using the following method:

CREATE TABLE example_table (
    id INT AUTO_INCREMENT PRIMARY KEY,
    created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);

In the example given, the `created_at` column is defined as a DATETIME type and a default value of the current timestamp is set using the `DEFAULT CURRENT_TIMESTAMP` syntax. This means that if no value is specified for the `created_at` column during data insertion, the current timestamp will automatically be used as the default value.

bannerAds