473,799 Members | 2,900 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

TIMESTAMP : created & modified fields ?

Hi all,

I have a number of tables that I want 'timestamped' with both a
modified and created 'timestamp' field.

Ideally both fields should 'work if ignored' in insert and updates,
thus the following is fine for a modified timestamp field tsm:

tsm timestamp default current_timesta mp on upate current_timesta mp

But is there a way to create a field that in effect is 'write once'
and contains the creation timestamp ? In a sense I want some thing
like (psudo sql create line):

tsc timestamp default current_timesta mp 'on_update_do_n othing'

I think a second timestamp with 'default current_time' would help but
mysql does not allow this - (I have no idea why !?)

There are quite a number of tables and I want to avoid 'table
specific' sql code like the following (psudo sql):

insert record ...
get last update auto increment key
select modifed timestamp value from key record
update key record create timestamp field with timestamp

Any ideas (for a 'write once' creation timestamp)?

Jan 4 '06 #1
2 4488
"Reddog" <_n************ ***@blueyonder. co.uk> wrote in message
news:i1******** *************** *********@4ax.c om...
I have a number of tables that I want 'timestamped' with both a
modified and created 'timestamp' field.

Any ideas (for a 'write once' creation timestamp)?


One method to do this is with triggers (requires MySQL 5.0). Define a
trigger on INSERT that forces the creation timestamp field to be the current
time, overriding any other value that the client may have attempted to
insert.

CREATE TRIGGER timestamp_ins_c heck BEFORE INSERT ON myTable
FOR EACH ROW
BEGIN
SET NEW.created = CURRENT_TIMESTA MP();
SET NEW.updated = CURRENT_TIMESTA MP();
END;

Also define a trigger on UPDATE that forces the creation timestamp field to
be unaltered from its pre-update value.

CREATE TRIGGER timestamp_upd_c heck BEFORE UPDATE ON myTable
FOR EACH ROW
BEGIN
SET NEW.created = OLD.created;
SET NEW.updated = CURRENT_TIMESTA MP();
END;

If you don't use MySQL 5.0, you may have to resort to application-level code
to enforce your rules.

Regards,
Bill K.
Jan 4 '06 #2
On Wed, 4 Jan 2006 11:40:52 -0800, "Bill Karwin" <bi**@karwin.co m>
wrote:

One method to do this is with triggers (requires MySQL 5.0). Define a
trigger on INSERT that forces the creation timestamp field to be the current
time, overriding any other value that the client may have attempted to
insert.
.... .....>If you don't use MySQL 5.0, you may have to resort to application-level code
to enforce your rules.

Regards,
Bill K.


Thanks for the info Bill,
I using MySql 4.1.7 NT so I have do not triggers yet.
Reddog.
Jan 5 '06 #3

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

Similar topics

0
1467
by: Bruno Batarelo | last post by:
Greetings for a while I simply can not import properly timestamp data back to database. I dump all databases with mysqldump --opt --all-databases > backup.sql and backup file is correctly created. All my tables have timestamp column since VB programs and MyODBC do not work properly without it. When I import data back, every timestamp column is restored to 0000-00-00 00:00:00. That is incorrect data and time format and my application...
1
1469
by: anagai | last post by:
I have a datetime field that records date and time. This field records when rec is created. I also have a timestamp field that records whenever the record is updated. I noticed that when i first create the record, the update time is about 3-5 minutes before the create time. The update time and create time has to be identical. How can one lag the other? Im executing sql from a php page.
7
1929
by: laurenq uantrell | last post by:
Is there any reason to have a row that is the PK/Identity and a row that is datatype Timestamp in the same table? Does this in any way help speeding up row updates? Thanks, lq
1
8000
by: Roger Twomey | last post by:
I have a database that I don't want to lock. I decided that before any updates can occur I would check a timestamp value and ensure that nobody else updated before I did (avoiding the 'last update wins' scenario). I have a problem, I can read the Timestamp from the db when I read the record. I currently use the data to pre-fill a form (gee go figure ;) ) and the user changes some values and updates. I don't know what to DO with the...
5
2712
by: Prabu Subroto | last post by:
Dear my friends... I created some tables with field timestamp (datatype also timestamp). I mean, I want to have the data when each record inserted or modified in the tables. on MysQL, I just need to define the column (field) with datatype "timestamp" and that's all. each time new record inserted than the timestamp value will be inserted automaticall. also for the data modification,
1
3829
by: Joseph Geretz | last post by:
I'm transferring a file from server to workstation, using Web Service Extensions and DIME. Along with the file, which travels as a DIME attachment, I'm also sending along metadata information about the file as it exists on the server. The metadata also travels as a DIME attachment in XML format. As you can see, the metadata contains several file timestamps. What I'm trying to do is set the local file timestamps for Created, Modified and...
0
1661
by: presley2 | last post by:
Hi, I want to create an auto creation date and update date in my mysql table. I am using the "MySQL Cookbook" approach, using the TIMESTAMP field which basically is: - create 2 new fields in the table (t_create and t_update) - both NULL - when a new record is created they both will register a common timestamp - when the record is modified the t_update will change, buit not the t_create
7
6117
by: JJ | last post by:
How do I set one field to have the updated timestamp, and another to have the created timestamp? I want to do this directly from code generated from DB Designer if possible?! JJ
1
5374
by: mhearne808[insert-at-sign-here]gmail[insert-dot-he | last post by:
Is is possible to get the timestamp of a file on a web server if it has a URL? For example, let's say that I want to know when the following file was created: http://www.w3schools.com/xml/note.xml I can get an HTTPMessage object using urllib2, like this:
0
10252
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10027
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9073
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7565
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5463
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4141
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3759
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.