SQL CURRENT_TIMESTAMP

The SQL CURRENT_TIMESTAMP function returns the current date and time of the database server. It is often used in database records to store timestamps for created or updated rows.

In this tutorial, we will explore the SQL CURRENT_TIMESTAMP function, its syntax, and practical examples demonstrating its usage.


Syntax of SQL CURRENT_TIMESTAMP

The basic syntax of the CURRENT_TIMESTAMP function is as follows:

</>
Copy
SELECT CURRENT_TIMESTAMP;

CURRENT_TIMESTAMP can also be used as a default value for a column in a table:

</>
Copy
CREATE TABLE users (
    id INT PRIMARY KEY AUTO_INCREMENT,
    name VARCHAR(50),
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

Step-by-Step Examples Using SQL CURRENT_TIMESTAMP

1 Fetching the Current Timestamp

To retrieve the current timestamp of the database server, we can use the following query:

</>
Copy
SELECT CURRENT_TIMESTAMP AS log_timestamp;