MySQL, phpMyAdmin: TIMESTAMP always executes the NOW function

Something very annoying is happening with my TIMESTAMPS ...

I have a column "createdat", "deletedat" and "updatedat" in my table ... I set my deleted item and updated it to NULL and DEFAULT NULL ... however, when a new record is added, the NOW () function always executed for deleteat and updatedat instead of just leaving it as NULL.

So I'm finishing: 00:00:00 ...

Why is this not just the default NULL?

Here is my table: enter image description here

Here when pasting (note the NOW function): enter image description here

The following SQL is executed:

INSERT INTO `MYTABLE_DEV`.`messages` (`id`, `fromUserId`, `toUserId`, `subject`, `body`, `createdat`, `updatedat`, `deletedat`) VALUES (NULL, '1', '3', 'Message', 'This is another message.', CURRENT_TIMESTAMP, NOW(), NOW());
+5
source share
4 answers

This is the expected behavior.

, MySQL TIMESTAMP now() , . TIMESTAMP.

: , TIMESTAMP, TIMESTAMP DEFAULT NULL .

, , DATETIME - .

SQL, :

create table timestamp_datatype (id int, dt datetime, ts timestamp);
-- test 1: leaving ts to default - you get now()
insert into timestamp_datatype (id, dt) values (1, '2011-01-01 01:01:01'); 
-- test 2: trying to give ts a value - this works
insert into timestamp_datatype (id, dt, ts) values (2, '2011-01-01 01:01:01', '2011-01-01 01:01:01');
-- test 3: specifying null for ts - this doesn't work - you get now()
insert into timestamp_datatype (id, dt, ts) values (3, '2011-01-01 01:01:01', null);
-- test 4: updating the row - ts is updated too
insert into timestamp_datatype (id, dt, ts) values (4, '2011-01-01 01:01:01', '2011-01-01 01:01:01');
update timestamp_datatype set dt = now() where id = 4; -- ts is updated to now()
select * from timestamp_datatype;
+------+---------------------+---------------------+
| id   | dt                  | ts                  |
+------+---------------------+---------------------+
|    1 | 2011-01-01 01:01:01 | 2011-07-05 09:50:24 |
|    2 | 2011-01-01 01:01:01 | 2011-01-01 01:01:01 |
|    3 | 2011-01-01 01:01:01 | 2011-07-05 09:50:24 |
|    4 | 2011-07-05 09:50:24 | 2011-07-05 09:50:24 |
+------+---------------------+---------------------+
+1

() . :

INSERT INTO `MYTABLE_DEV`.`messages` (`id`, `fromUserId`, `toUserId`, `subject`, `body`) VALUES (NULL, '1', '3', 'Message', 'This is another message.');

...

INSERT INTO `MYTABLE_DEV`.`messages` (`id`, `fromUserId`, `toUserId`, `subject`, `body`, `createdat`, `updatedat`, `deletedat`) VALUES (NULL, '1', '3', 'Message', 'This is another message.', CURRENT_TIMESTAMP, NULL, NULL);
+1

( , 3.5.2, ):

+1

/ phpMyAdmin. , 2010-06-13 11:06:47 UTC. :

, , NOW() INSERT/UPDATE, NULL. , , - NULL.

, , phpMyAdmin. phpMyAdmin, .

0

All Articles