473,473 Members | 2,357 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Incrementing or updating a TIMESTAMP field.

Hi,

I'm in the process of implementing a multi-user system containing an
adjacency list (tree structure). I'm using a TIMESTAMP field on each
record in the adjacency list in order to tell when a node has been changed
since the last read. Sometimes though, it is useful to flag a "parent" (or
all ancestors or a node) as being changed if any of its children have. Is
there any way I can force an update to the parent TIMESTAMP field without
actually modifying any of the other fields in the record? Something like
this (assuming I have a field called [Timestamp]):

UPDATE Adjacency SET [Timestamp] = [Timestamp] + 1 WHERE ID = @_In_ID

Now, will the timestamp be incremented here by 1, or will SQL server get
confused as in theory it must "update the timestamp after updating the
timestamp" for this record?

Thanks,

Robin

Jul 23 '05 #1
3 3856
You can't update a timestamp. You could do this:

UPDATE Adjacency
SET some_column = some_column
WHERE ...

Be aware that update triggers will also fire if you have them.
--
David Portas
SQL Server MVP
--

Jul 23 '05 #2
Tables are files; rows are not records; columns are not fields. You
are still thinking in the terms of a 1950's file system, which is
probably what lead to the adjacency list model -- it looks like pointer
chains instead of sets.
I'm using a TIMESTAMP fie*ld [sic] on each record [sic] in the

adjacency list in order to tell when a node ha*s been changed since
the last read. Sometimes though, it is useful to flag* a "parent" (or
all ancestors or a node) as being changed if any of its chil*dren
have. Is there any way I can force an update to the parent TIMESTAMP
*field [sic] without actually modifying any of the other fields [sic]
in the record [sic] ? <<

Want to move over to the Nested sets model and make life easier?
First put the nodes in their own table and the tree structure in
another.

--update all superiors
UPDATE Nodes
SET last_change_date = CURRENT_TIMESTAMP
WHERE node-id
IN (SELECT T2.node_id
FROM Tree AS T1, Tree AS T2
WHERE T1.lft BETWEEN T2.lft AND T2.rgt
AND T1.node_id = @:my_node_id;

--update imediate superior only
UPDATE Nodes
SET last_change_date = CURRENT_TIMESTAMP
WHERE node-id
IN (SELECT B.node_id AS boss
FROM Tree AS E
LEFT OUTER JOIN
Tree AS B
ON B.lft
= (SELECT MAX(lft)
FROM Tree AS S
WHERE E.lft > S.lft
AND E.lft < S.rgt));

Get a copy of my book TREES & HIERARCHIES IN SQL for details and code
samples.

Jul 23 '05 #3
Hi Celko,

I followed your ideas and actually tried out an implementation of nested
sets at some point in the past (about 1 year ago). It was a neat solution
but suffered from not being quite as comprehensible as simply storing a path
string to each node and also if suffers from the requirement that
modifications to a node (insert for example) results in the potential
renumbering of many nodes in the subtree.

In the interests of future maintenance I wanted something basic and didn't
care too much about performance (within reason). I also had a go at
Tropashenkos (I think) materialized path (using binary fractions)! This was
a miserable failure due to numerical accuracy and unbelievably slow
performance (on SQL Server).

Anyway, interesting stuff.

Robin

"--CELKO--" <jc*******@earthlink.net> wrote in message
news:11**********************@c13g2000cwb.googlegr oups.com...
Tables are files; rows are not records; columns are not fields. You
are still thinking in the terms of a 1950's file system, which is
probably what lead to the adjacency list model -- it looks like pointer
chains instead of sets.
I'm using a TIMESTAMP fie*ld [sic] on each record [sic] in the

adjacency list in order to tell when a node ha*s been changed since
the last read. Sometimes though, it is useful to flag* a "parent" (or
all ancestors or a node) as being changed if any of its chil*dren
have. Is there any way I can force an update to the parent TIMESTAMP
*field [sic] without actually modifying any of the other fields [sic]
in the record [sic] ? <<

Want to move over to the Nested sets model and make life easier?
First put the nodes in their own table and the tree structure in
another.

--update all superiors
UPDATE Nodes
SET last_change_date = CURRENT_TIMESTAMP
WHERE node-id
IN (SELECT T2.node_id
FROM Tree AS T1, Tree AS T2
WHERE T1.lft BETWEEN T2.lft AND T2.rgt
AND T1.node_id = @:my_node_id;

--update imediate superior only
UPDATE Nodes
SET last_change_date = CURRENT_TIMESTAMP
WHERE node-id
IN (SELECT B.node_id AS boss
FROM Tree AS E
LEFT OUTER JOIN
Tree AS B
ON B.lft
= (SELECT MAX(lft)
FROM Tree AS S
WHERE E.lft > S.lft
AND E.lft < S.rgt));

Get a copy of my book TREES & HIERARCHIES IN SQL for details and code
samples.
Jul 23 '05 #4

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

Similar topics

11
by: Jason | last post by:
Let's say I have an html form with 20 or 30 fields in it. The form submits the fields via POST to a php page which updates a table in a database with the $_POST vars. Which makes more sense? ...
4
by: Jimmy Jim | last post by:
OK, I have a datetime field in a table and when I ran an update like so: UPDATE myTable SET number=2 WHERE ID=50 I had the old datetime information in the table and that got overwritten when...
3
by: Andreas | last post by:
Hello list, I suspect, this is a common issue for newbies. Is there a simple way to have an auto-updating timestamp like mysql has ? create table something ( id int4, sometext...
3
by: Tc | last post by:
Hi, I was curious, I am thinking of writing an application that loads a dataset from a database that resides on a server. The question I have is this, if multiple copies of the app will be...
5
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...
0
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...
2
by: Reddog | last post by:
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...
22
by: Mal Ball | last post by:
I hope I have the right forum for this question. I have an existing Windows application which uses a SQL Server database and stored procedures. I am now developing a web application to use the same...
1
by: McGowan | last post by:
Hey, I'm wondering how I can get an update statement to work with data being passed through the URL. the problem is that the statement needs to work no matter what table is being worked on as any...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
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,...
1
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.