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
 Old Forums
 CLOSED - General SQL Server
 Preventing two users changing

Author  Topic 

SqlFriend
Starting Member

26 Posts

Posted - 2004-09-01 : 16:47:42

I have these sets of data I will call "files" for the purpose of this note. I want users to be able to "check out" files and then no one else can modify them while this user has it. When they are done modifying it, they check it back in.

How would you handle this? Is there a test and set method which occurs in a unary way I could do on a column?


How would you handle if a user checked out something and then did nothing with it for an extended period.. would you automatically check it back in? Allow for someone else to "steal" the checkout after a day? And then what if after that day passes the user decides to actually check in the changes?

DustinMichaels
Constraint Violating Yak Guru

464 Posts

Posted - 2004-09-01 : 16:52:58
You could have a column indicating if the item is checked out and the date/time it was checked out.

If the user has the item for to long you could use the date/time attribute of the record to determine if the user's lock should be broken.

Dustin Michaels
Go to Top of Page

SqlFriend
Starting Member

26 Posts

Posted - 2004-09-01 : 17:03:33

I like that idea- but what if two people set it at the same moment?

I guess you could have them update where primary key matches and also checked out = false- then look at the result and see if they actually got it
Go to Top of Page

DustinMichaels
Constraint Violating Yak Guru

464 Posts

Posted - 2004-09-01 : 17:54:03
If two people try to update it at the same time then you have to trust sql server to make sure only one person gets exclusive control of the item. If you need to you may need to put a lock on the table if your paranoid

Dustin Michaels
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2004-09-01 : 18:32:31
You need an Update datetime column...and possibly an update by to know who

And in one trans, check then datetime, and if it less than the time you got the data, then update, else return the data of the updated row....

Or not....and let fate decide....

You need to think about overhead....



Brett

8-)
Go to Top of Page
   

- Advertisement -