- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What would happen if we insert empty values in a table with a column set as type TIMESTAMP CURRENT_TIMESTAMP?
152 Lectures 16 hours
87 Lectures 5.5 hours
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)
- Can we use current_date() for table with column timestamp default in MySQL?
- How can we insert current year automatically in a YEAR type column of MySQL table?
- Creating a table with a TIMESTAMP field in MySQL?
- How to check if a timestamp is set in MySQL?
- What will happen if we have set UNIQUE and multiple insertion with duplicate values
- What would happen if we run SELECT WHERE columnName = zero in MySQL?
- Set current date and time to timestamp in MySQL
- How to update a Timestamp and set to current date in MongoDB?
- What would happen if there were no Moon?
- How can we insert current date automatically in a column of MySQL table?
- What happens when you insert nothing after declaring a column “timestamp default CURRENT_TIMESTAMP”?
- How to add a “created at” column in a table to set the timestamp in MySQL?
- Get two days data (today and yesterday) from a MySQL table with timestamp values
- How to set NULL values in a table column and insert the same
- Execute INSERT if table is empty in MySQL?