Inserting NULL into MySQL timestamp

You can insert and update NULL into a MySQL timestamp.

Create the table:

create table penguins(id int primary key auto_increment, the_time timestamp NULL);

Insert some rows:

insert into penguins(the_time) values (now());
insert into penguins(the_time) values (null);
insert into penguins(the_time) values (0);
insert into penguins(the_time) values ('1999-10-10 01:02:03');

Which prints:

select * from penguins

1   2015-01-23 15:40:36
2   
3   0000-00-00 00:00:00
4   1999-10-10 01:02:03

The column called the_time with datatype: timestamp in 2nd row has the value NULL.


http://dev.mysql.com/doc/refman/5.0/en/timestamp-initialization.html

In addition, you can initialize or update any TIMESTAMP column to the current date and time by assigning it a NULL value, unless it has been defined with the NULL attribute to permit NULL values.

In order to allow a TIMESTAMP to be nullable, create it using the NULL attribute, or alter the table and add the NULL attribute. In a create statement, it would resemble.

CREATE TABLE t1 (tsvalue TIMESTAMP NULL, ... );

Inserting a NULL value into a TIMESTAMP field with the NULL attribute set will result in the field being set to NULL instead of to NOW().