
- 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
What would happen if we insert empty values in a table with a column set as type TIMESTAMP CURRENT_TIMESTAMP?
If we will insert nothing in the INSERT statement, then for timestamp type, it would insert the current date-time. Let us first create a table −
mysql> create table DemoTable -> ( -> UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> UserLoginDate timestamp default current_timestamp -> ); Query OK, 0 rows affected (0.61 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values(); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values(); Query OK, 1 row affected (0.08 sec) mysql> insert into DemoTable(UserId) values(null); Query OK, 1 row affected (0.13 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+--------+---------------------+ | UserId | UserLoginDate | +--------+---------------------+ | 1 | 2019-11-03 12:55:44 | | 2 | 2019-11-03 12:55:45 | | 3 | 2019-11-03 12:55:46 | | 4 | 2019-11-03 12:56:06 | +--------+---------------------+ 4 rows in set (0.00 sec)
- Related Articles
- What happens when you insert nothing after declaring a column “timestamp default CURRENT_TIMESTAMP”?
- How to set NULL values in a table column and insert the same
- What will happen if we have set UNIQUE and multiple insertion with duplicate values
- How can we insert current year automatically in a YEAR type column of MySQL table?
- Can we use current_date() for table with column timestamp default in MySQL?
- Execute INSERT if table is empty in MySQL?
- Insertion in a MySQL table with only a single column set as auto_increment?
- What role data type plays when I insert an empty string into a MySQL column which is declared as NOT NULL?
- Can we insert records in a MySQL table without auto_increment values?
- What would happen if we run SELECT WHERE columnName = zero in MySQL?
- How to add a “created at” column in a table to set the timestamp in MySQL?
- How to insert NULL keyword as a value in a character type column of MySQL table having NOT NULL constraint?
- Return only the non-empty and non-null values from a table and fill the empty and NULL values with the corresponding column values in MySQL?
- How to insert an array of values in a MySQL table with a single INSERT?
- Can I define a column as a table type in SAP HANA?

Advertisements