Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6110397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:30:39+00:00 2026-05-23T14:30:39+00:00

There’s something very irritating going on with my TIMESTAMPS … I have a createdat,

  • 0

There’s something very irritating going on with my TIMESTAMPS …

I have a “createdat”, “deletedat” and “updatedat” column in my Table… I’ve set my deletedat and updated at to NULL and DEFAULT NULL … however, when a new record is added, the NOW() function is always executed for deletedat and updatedat instead of just leaving it as NULL.

So I end up with: 00:00:00 …

Why isn’t it just defaulting to NULL?

Here’s my Table:
enter image description here

Here’s when Inserting (notice the NOW function is selected):
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());
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T14:30:40+00:00Added an answer on May 23, 2026 at 2:30 pm

    This is expected behaviour.

    Unlike other databases, in MySQL TIMESTAMP columns are ALWAYS updated with now() whenever the row is updated. This is a deliberate feature of the TIMESTAMP datatype.

    Edit: Note that I am talking here about TIMESTAMP, not TIMESTAMP DEFAULT NULL or any other variations.

    What you want is a DATETIME datatype – they behave as normal columns.

    Here’s some test SQL to show its behaviour:

    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 |
    +------+---------------------+---------------------+
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There is a column that exists in 2 tables. In table 1, this column
There can only be one IDENTITY column per table Why is it so? Take
There are two table s : one is the master and one the detail
There is any way to set the generic type (T) of class in the
There's a column on one of my tables that's being updated by various INSERT/DELETE
There are are 150 000 records in my comments table and about 1000 new
There are 3 different ways to get data out of a BLOB column from
There's obviously something I'm missing here - I've been through the developer.android reference and
There are two vectors std :: vector and QVector . We have to check
There's a webpage with something annoying on it which I'd like to hide every

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.