> Thanks Tibor. Can I release the lock before commit tran?
No. Keep the transactions as short as possible, make sure you have proper indexes to minimize the
amount of data needed to be locked and if needed you can do dirty reads (see for instance the NOLOCK
"nonno" <nonno@discussions.microsoft.com> wrote in message
news:AED6C9BD-D3EF-4751-BF94-9921121B5876@microsoft.com...
> Thanks Tibor. Can I release the lock before commit tran? How to do that? It's
> too long to wait for the whole transaction to commit!
>
> "Tibor Karaszi" wrote:
>
>> Nesting transaction only exist in syntax, not semantics. The outer BEGIN TRAN begins the
>> transaction. When @@TRANCOUNT is zero, the transaction is ended. BEGIN TRAN increases nesting
>> level
>> with 1, COMMIT decreases with 1 and ROLLBACK brings nesting level to 0.
>>
>> --
>> Tibor Karaszi, SQL Server MVP
>>
http://www.karaszi.com/sqlserver/default.asp >>
http://www.solidqualitylearning.com/ >>
>>
>> "nonno" <nonno@discussions.microsoft.com> wrote in message
>> news:7111C36D-453C-4B4B-B953-A2DDDD5B130D@microsoft.com...
>> > thanks Wayne. You said something will be locked for the duration of the
>> > transaction, how about nesting transaction? Will that be locked for the
>> > duration of the nested transaction only or the entire transaction?
>> >
>> > "Wayne Snyder" wrote:
>> >
>> >> The scope of the lock is determined by the plan that the optimizer
>> >> chooses.... If the optimizer chooses row level locks, then only the row will
>> >> be locked, however the optimizer may choose a page level lock, and all rows
>> >> on the page will be locked for the duration of the transaction....
>> >>
>> >> --
>> >> Wayne Snyder, MCDBA, SQL Server MVP
>> >> Mariner, Charlotte, NC
>> >>
www.mariner-usa.com >> >> (Please respond only to the newsgroups.)
>> >>
>> >> I support the Professional Association of SQL Server (PASS) and it's
>> >> community of SQL Server professionals.
>> >>
www.sqlpass.org >> >>
>> >> "nonno" <nonno@discussions.microsoft.com> wrote in message
>> >> news:62DE9428-A895-44FA-87A8-832D20E3F7FE@microsoft.com...
>> >> > hi, I have a few questions about holdlock, e.g.
>> >> > begin tran
>> >> > ...
>> >> > select @last_val = max(col1) from table1 (HOLDLOCK) where col2 = 'X'
>> >> > ...
>> >> > insert table1 (col1, col2) values (@last_val + 1, 'X')
>> >> > ...
>> >> > commit tran
>> >> > What will be locked here (the entire table1 or only the rows with
>> >> > col2='X') ?
>> >> > Will it be locked until the transaction completed?
>> >> > This program is running in a multiuser environment, I want to restrict
>> >> > that
>> >> > only 1 session at a time can insert a row into table1 with a particular
>> >> > value
>> >> > of col2, e.g. if session1 try to insert a row in table1 with col2='A'
>> >> > while
>> >> > session2 inserting a row with col2='A', session1 will be blocked until
>> >> > session2 transaction completed; if session1 try to insert a row in table1
>> >> > with of col2='B' while session2 inserting a row with col2='A', session1
>> >> > will
>> >> > not be blocked. How can I do this?
>> >>
>> >>
>> >>
>>
>>
>>