Getting a list of updated rows?

This is a discussion on Getting a list of updated rows? within the MySQL Database forums, part of the Database Forums category; If I run an UPDATE statement, is there any statement I can then run which will return a list of ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 09-08-2007
Adam Atlas
 
Posts: n/a
Default Getting a list of updated rows?

If I run an UPDATE statement, is there any statement I can then run
which will return a list of the primary keys of all the rows updated
in the previous query? Or can that only be done by running a `SELECT
id` (etc.) with the same WHERE conditions before doing the UPDATE?

Reply With Quote
  #2 (permalink)  
Old 09-08-2007
strawberry
 
Posts: n/a
Default Re: Getting a list of updated rows?

On 8 Sep, 16:06, Adam Atlas <a...@atlas.st> wrote:
> If I run an UPDATE statement, is there any statement I can then run
> which will return a list of the primary keys of all the rows updated
> in the previous query? Or can that only be done by running a `SELECT
> id` (etc.) with the same WHERE conditions before doing the UPDATE?


Why not have a 'last_updated' column with a timestamp. Then you can
just select all rows updated after the query was executed.


Reply With Quote
  #3 (permalink)  
Old 09-08-2007
Brian Wakem
 
Posts: n/a
Default Re: Getting a list of updated rows?

strawberry wrote:

> On 8 Sep, 16:06, Adam Atlas <a...@atlas.st> wrote:
>> If I run an UPDATE statement, is there any statement I can then run
>> which will return a list of the primary keys of all the rows updated
>> in the previous query? Or can that only be done by running a `SELECT
>> id` (etc.) with the same WHERE conditions before doing the UPDATE?

>
> Why not have a 'last_updated' column with a timestamp. Then you can
> just select all rows updated after the query was executed.



That would not work because other processes could make update before you
executed that query.


--
Brian Wakem
Reply With Quote
  #4 (permalink)  
Old 09-08-2007
strawberry
 
Posts: n/a
Default Re: Getting a list of updated rows?

On 8 Sep, 20:30, Brian Wakem <n...@email.com> wrote:
> strawberry wrote:
> > On 8 Sep, 16:06, Adam Atlas <a...@atlas.st> wrote:
> >> If I run an UPDATE statement, is there any statement I can then run
> >> which will return a list of the primary keys of all the rows updated
> >> in the previous query? Or can that only be done by running a `SELECT
> >> id` (etc.) with the same WHERE conditions before doing the UPDATE?

>
> > Why not have a 'last_updated' column with a timestamp. Then you can
> > just select all rows updated after the query was executed.

>
> That would not work because other processes could make update before you
> executed that query.
>
> --
> Brian Wakem


Hey, if you've got a better solution, share it with us. I'm here to
learn too.

Reply With Quote
  #5 (permalink)  
Old 09-08-2007
Brian Wakem
 
Posts: n/a
Default Re: Getting a list of updated rows?

strawberry wrote:

> On 8 Sep, 20:30, Brian Wakem <n...@email.com> wrote:
>> strawberry wrote:
>> > On 8 Sep, 16:06, Adam Atlas <a...@atlas.st> wrote:
>> >> If I run an UPDATE statement, is there any statement I can then run
>> >> which will return a list of the primary keys of all the rows updated
>> >> in the previous query? Or can that only be done by running a `SELECT
>> >> id` (etc.) with the same WHERE conditions before doing the UPDATE?

>>
>> > Why not have a 'last_updated' column with a timestamp. Then you can
>> > just select all rows updated after the query was executed.

>>
>> That would not work because other processes could make update before you
>> executed that query.
>>
>> --
>> Brian Wakem

>
> Hey, if you've got a better solution, share it with us. I'm here to
> learn too.



The only way I can think of is to LOCK the table(s) first, then SELECT using
the same WHERE clause you intend to use in the UPDATE.

Then UPDATE and UNLOCK.


--
Brian Wakem
Reply With Quote
  #6 (permalink)  
Old 09-09-2007
Kenoli
 
Posts: n/a
Default Re: Getting a list of updated rows?

If you are updating on the primary keys, then you already know what
those are. If you are updating on a secondary key or non-key field,
you could do a query returning the primary keys associated with the
field you are using to select records for update.

One issue might arise if you are sending a query that does not contain
data to for some records and want to know primary keys associated only
with the records for which you are sending data, i.e. those actually
updated. In this case, you could test your update data in php, see
which key fields your script was sending data for and proceed as
described above.

Seems pretty straightforward, or am I missing something?

--Kenoli

On Sep 8, 8:06 am, Adam Atlas <a...@atlas.st> wrote:
> If I run an UPDATE statement, is there any statement I can then run
> which will return a list of the primary keys of all the rows updated
> in the previous query? Or can that only be done by running a `SELECT
> id` (etc.) with the same WHERE conditions before doing the UPDATE?



Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 06:03 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0