Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 .NET Inside SQL Server (2005)
 Multiple requests that where order matters

Author  Topic 

sadffffff
Starting Member

1 Post

Posted - 2009-07-04 : 00:32:34
Considering this scenario:

a user clicks a submit button on a forum to edit their post. the action for the submit button is to save the old message into a history table and then updates the message with the edited information.

so it would be an insert statement that selects the data from the current message and puts it in history. and then an update statement that changes the current message.

the order here is crucial because two connection editing the same post could cause an issue where requester1 makes the move to the history table and then hits some sort of lag, and then takes too long to make the post change, then requester2 comes in, moves data to the history table and updates the current post. THEN requester1 continues and edits the post with his data. in that scenario, requester2's changes are lost forever.

so what needs to happen is for the statements to be run together so there is not possibility to gap between them.

i suppose a better way of doing this would be to not move data around like that and just make a new post and load that in place of the old one. this would seem to require more searching of the database for non-editing operation, though. so is there a way to do it the way i initially destribed?

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-07-04 : 11:09:10
Since SQL Server 2005 you can use UPDATE with OUTPUT-clause.
That's what you need to use only one statement.
http://msdn.microsoft.com/en-us/library/ms177564(SQL.90).aspx

Fred


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -