Skip to content

TIMESTAMP

CREATE TABLE Employees (
id INT PRIMARY KEY,
name VARCHAR(20),
registered TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
INSERT INTO Employees (id, name) VALUES (1, 'John');
SELECT * FROM Employees;
idnameregistered
1John2022-01-11 17:15:12

The TIMESTAMP data type is used in the CREATE TABLE statement to create a new table Employees. The registered column has the TIMESTAMP data type, and its default value is set to CURRENT_TIMESTAMP. When a new row is inserted into the Employees table without specifying a value for the registered column, MySQL will automatically use the current timestamp. Therefore, when we insert ‘John’ into the Employees table without specifying a value for registered, the value is automatically set to the current timestamp.