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.
| Author |
Topic |
|
kelkins
Starting Member
4 Posts |
Posted - 2010-12-17 : 13:56:10
|
| Hi guys, I have a problem with a java servlet that I am writing.I have a table which has some base 36 values in it. I need to:-lock the table-select these base 36 numbers -increase their value by one (in java)-save the new values to variables in my servlet (the values are used to write to other tables)-update the table with the new values-unlock the tableI have been unsuccessful in finding a way to do this without releasing the lock after I initially select the values. The table needs to be locked from reads and writes until after the values are updated. Thanks in advance.Edit: This is a SQL Server 2005 database. |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
kelkins
Starting Member
4 Posts |
Posted - 2010-12-17 : 14:40:35
|
| I looked at TABLOCKX, but the problem is that the lock is released once you execute the statement. I have to execute it in order to get the current values to convert before I can write them back to the table. I could theoretically lock both transactions, but that still leaves a little time between them that something else could happen to the table.Is there a SQL command that I can use that will lock the table until I tell it to unlock? |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
kelkins
Starting Member
4 Posts |
Posted - 2010-12-17 : 14:55:58
|
| When I "BEGIN TRANSACTION" will this lock the entire database or just the tables that are specified in the statements that follow? |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
kelkins
Starting Member
4 Posts |
Posted - 2010-12-17 : 15:06:22
|
| Awesome! Thanks you so much for your help :0) |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
|
|
|