Blocking updates of a table
Hi,
I've been trying to design a way for me to issue a transaction that:
- Block all inserts on a table when row X has a certain value (call it A)
- Add a row to the table with row X containing A
- Add rows to another table
- Unblock inserts
- Commit transaction
Is this possible? Can anyone give me some pointers as to what to do?
Thanks in advance!
[424 byte] By [
someguy] at [2008-2-18]
For (1) and (2)
While inserting the row that has a certain value (A), you can request a TABLOCKX. This will acquire X lock on the table and there by block other inserts by other concurrent transactions.
For (3): Is it like any other insert to another table? In that case, nothing special needs to be done
Thanks
Sunil Agarwal
For 3 that is what I meant.
For 1 and 2, it sounds like TABLOCKX locks the whole table exclusively (from what I can find in Books Online) - have I read it correctly? Is there any way to block other transactions from inserting rows (while the first transaction is not yet commited) when a table key column (A in my original post) is a certain value (X in my original post) - rather than just locking the whole table?
Thanks for your help!
I assume you only want to block Inserts but not Updates, Deletes and SELECTS.
You could try using an Insert trigger that would rollback the other transactions until a condition has been achieved.