Re: Quick question re: locks and triggers
From: Louis Davidson (dr_dontspamme_sql_at_hotmail.com)
Date: 08/05/04
- Next message: Joe Celko: "Re: find sequence of numbers"
- Previous message: Louis Davidson: "Re: find sequence of numbers"
- In reply to: Tibor Karaszi: "Re: Quick question re: locks and triggers"
- Next in thread: Steve: "Re: Quick question re: locks and triggers"
- Reply: Steve: "Re: Quick question re: locks and triggers"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 5 Aug 2004 11:08:17 -0500
Yeah, without an exclusive lock held during the trigger, if you decided to
rollback your transaction, you might have to wait for another user to
release their locks on your object before you could roll back. Clearly not
what would be desired.
> > ie: is it therefore impossible for another process to
> > insert until the trigger has finished it's work ??
I think the question here is slightly different that the other question
asked. The exclusive lock is only on the row being inserted, not the entire
table. If you are seeing table locks when you do updates, inserts, or
delete, then you are having problems with indexing, in that the entire table
had to be searched for some criteria. Shouldn't happen on an insert without
a trigger or check constraints involving UDF's that access tables.
So the exclusive row (or very seldomly page) lock is seldom a problem being
held for the length of the transaction in terms of blocking other WRITERS to
the table. Any other users trying to read that row in a SELECT statement
are going to have to cool their jets until the trigger(s) have completed,
and all transactions (not just the automatic implicit one caused by the
modification statement) have been ended and @@trancount = 0
-- ---------------------------------------------------------------------------- Louis Davidson (drsql@hotmail.com) Compass Technology Management Pro SQL Server 2000 Database Design http://www.apress.com/book/bookDisplay.html?bID=266 Note: Please reply to the newsgroups only unless you are interested in consulting services. All other replies will be ignored :) "Tibor Karaszi" <tibor_please.no.email_karaszi@hotmail.nomail.com> wrote in message news:uVaFXJveEHA.3792@TK2MSFTNGP09.phx.gbl... > Yes, the trigger will hold the lock. It would be very difficult for MS to implement rollback functionality in > a trigger if it didn't... > > -- > Tibor Karaszi, SQL Server MVP > http://www.karaszi.com/sqlserver/default.asp > http://www.solidqualitylearning.com/ > > > "Steve" <anonymous@discussions.microsoft.com> wrote in message news:09de01c47aee$8afa6f90$a601280a@phx.gbl... > > Hi all, > > > > Just learning about triggers and have a quick question. > > An insert statement holds an exclusive lock whilst the new > > row is written. What happens to the lock when an AFTER > > INSERT trigger is involved ?? Does the trigger hold the > > exclusive lock until it has terminated and the result > > returned to the client ?? > > > > ie: is it therefore impossible for another process to > > insert until the trigger has finished it's work ?? > > > > thanks > > Steve > > > >
- Next message: Joe Celko: "Re: find sequence of numbers"
- Previous message: Louis Davidson: "Re: find sequence of numbers"
- In reply to: Tibor Karaszi: "Re: Quick question re: locks and triggers"
- Next in thread: Steve: "Re: Quick question re: locks and triggers"
- Reply: Steve: "Re: Quick question re: locks and triggers"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|