
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 Questions & Answers
- 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?
- Set new delay time in a MySQL column
- How to create boolean column in MySQL with false as default value?
- 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?
- Present date as default value in a table
- Adding a new NOT NULL column to an existing table with records
- How to set default date time as system date time in MySQL?
- Concatenate all the columns in a single new column with MySQL
- How to modify column default value in MySQL?
Advertisements