
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
Adding a new column with the current time as a default value in MySQL?
For this, you can use the DEFAULT CURRENT_TIMESTAMP clause in MySQL. Following is the syntax −
CREATE TABLE yourTableName ( yourColumnName1 dataType1, yourColumnName timestamp DEFAULT CURRENT_TIMESTAMP );
Let us first create a table −
mysql> create table DemoTable -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> DueDate timestamp default current_timestamp -> ); Query OK, 0 rows affected (0.86 sec)
Now you can insert some records in the table using insert command −
mysql> insert into DemoTable values(); Query OK, 1 row affected (0.16 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
+----+---------------------+ | Id | DueDate | +----+---------------------+ | 1 | 2019-06-08 21:35:58 | +----+---------------------+ 1 row in set (0.00 sec)
- Related Articles
- Adding new column after a specific column and defining a default in MySQL?
- Adding a column whose value is not null by default in MySQL?
- How to create boolean column in MySQL with false as default value?
- Set new delay time in a MySQL column
- Creating a Table in MySQL to set current date as default
- Updating default value of new column in SAP system
- Set default value to a JSON type column in MySQL?
- Create a new table in MySQL with specific options with DEFAULT?
- How do I set the default value for a column in MySQL?
- Adding new enum column to an existing MySQL table?
- How to modify column default value in MySQL?
- Adding a new NOT NULL column to an existing table with records
- Concatenate all the columns in a single new column with MySQL
- Add a new value to a column of data type enum in MySQL?
- Adding a new column to existing DataFrame in Pandas in Python

Advertisements