Inserting NULL into MySQL timestamp Inserting NULL into MySQL timestamp sql sql

Inserting NULL into MySQL timestamp


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().


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 penguins1   2015-01-23 15:40:362   3   0000-00-00 00:00:004   1999-10-10 01:02:03

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


You need to change the default value for the hireDate column. Default value should be null

This

create table temp(id int, hireDate timestamp default 0);

Should be this:

create table temp(id int, hireDate timestamp null);