473,326 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

NOW() in inserts updates implicitly

Sorry for cross posting, just realised myodbc wasn't the place for
this:

Hello,

I'm having a problem with records inserted using NOW() as data in a
field having that timestamp updated when I alter another field. I am
using MySQL version 5.0.20-nt. To replicate:

use test;
CREATE TABLE date_test ( id INT, inserted TIMESTAMP, randomtext
VARCHAR(25) );
INSERT INTO date_test VALUES ( 1, NOW(), "Need water" );
INSERT INTO date_test VALUES ( 2, NOW(), "Very Thirsty" );
SELECT * FROM date_test;
+------+---------------------+--------------+
| id | inserted | randomtext |
+------+---------------------+--------------+
| 1 | 2006-06-26 14:56:43 | Need water |
| 2 | 2006-06-26 14:56:43 | Very Thirsty |
+------+---------------------+--------------+
2 rows in set (0.00 sec)
UPDATE date_test SET randomtext = "blah" WHERE id = 2;
mysql> SELECT * FROM date_test;
+------+---------------------+------------+
| id | inserted | randomtext |
+------+---------------------+------------+
| 1 | 2006-06-26 14:56:43 | Need water |
| 2 | 2006-06-26 14:57:06 | blah |
+------+---------------------+------------+
2 rows in set (0.00 sec)

You can see that the timestamp for the record with id 2 has changed its
time, even though it was not a part of the UPDATE statement.

I've looked through the documentation for NOW() on the MySQL document
site, and tried a variety of google searches with no luck. Does anybody
have a solution for this?

Jun 26 '06 #1
2 1559

raisinodd wrote:
I'm having a problem with records inserted using NOW() as data in a
field having that timestamp updated when I alter another field. I am
using MySQL version 5.0.20-nt. ... You can see that the timestamp for the record with id 2 has changed its
time, even though it was not a part of the UPDATE statement.


That's what a TIMESTAMP does, it stamps the time into a field
automatically ON UPDATE.
For a date created field, just use a DATETIME datatype, then it can be
populated with NOW() for the INSERT and it will persist until you
change it intentionally.

-David Hedrick Skarjune

Jun 26 '06 #2
That's it. Thanks very much for the quick reply!

Skarjune wrote:
raisinodd wrote:
I'm having a problem with records inserted using NOW() as data in a
field having that timestamp updated when I alter another field. I am
using MySQL version 5.0.20-nt. ...

You can see that the timestamp for the record with id 2 has changed its
time, even though it was not a part of the UPDATE statement.


That's what a TIMESTAMP does, it stamps the time into a field
automatically ON UPDATE.
For a date created field, just use a DATETIME datatype, then it can be
populated with NOW() for the INSERT and it will persist until you
change it intentionally.

-David Hedrick Skarjune


Jun 27 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: kerri | last post by:
Hi, I need to do a mysqldump of specific inserts, updates & deletes. I read in the docs that I can use -w or --where. Can I do a join? Could someone provide an example? Is there another...
3
by: Viswanatha Thalakola | last post by:
Hello, Can someone point me to getting the total number of inserts and updates on a table over a period of time? I just want to measure the insert and update activity on the tables. Thanks....
1
by: Craig Stadler | last post by:
Using mysql 4.0.23- What is the best way to execute several (hundreds of) inserts and updates? Rather than issuing tons of individual inserts and updates, can I send the strings to a text file...
0
by: Steve - DND | last post by:
Is there a way to perform multiple inserts and updates to SQL Server with stored procedures and the Command object's named parameters all at once? The only way to do this that I'm gathering so far...
0
by: Eric Paul | last post by:
I have been in search of a better way to handle bulk inserts and updates into SQL 2000 using c# and while I have found a few different ways to accomplish this I was wondering what is considered to...
0
by: Benzine | last post by:
I recently rolled out replication on our production server (MS SQL 2000 SP4) and every time a subscriber tries to sync the following always appears in the Merge Agent History: "Downloaded 100...
0
by: Dimitris Milonas | last post by:
Hello to all, I have a DetailView on a page with Insert/Update enable and Paging enable. I would like to have on the same page two buttons ("Submit" and "Cancel") where with the first ("Submit")...
0
by: jehrich | last post by:
Hi Everyone, I am a bit of a hobby programmer (read newbie), and I have been searching for a solution to a SQL problem for a recent pet project. I discovered that there are a number of brilliant...
4
by: shreyask | last post by:
I have been working on doing bulk updates and inserts through sqlapi++ using a bulk udpate extention library, developed, a long time ago, internally. The database is oracle. The bulk inserts/updates...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.