none
What is Mutex error in Triggers?

    Question

  • Few weeks back I was puzzled by this question asked by an Interviewer?

    I simple told him I haven't faced this error yet and he was amazed, "You are developing Triggers and don't know about this?"

     

    Anyone, please help... so that next time I'm prepared.


    ~Manu
    http://sqlwithmanoj.wordpress.com
    Friday, December 10, 2010 5:55 PM

Answers

  • The only use of "mutex" that I know of is for a mechanism for re-entrant code that can't be simultaneously executed by multiple processes to force that code to be single threaded.  It's not a typical SQL Server term.  If it were, it would apply as much to stored procedures as triggers.  Generally, in a well designed database with well written code, this would be handled by using standard data locking and transactions.

    If there was some reason, you needed to do this in SQL with something other than data locking, you could use sp_getapplock and sp_releaseapplock to get a hook into the SQL Server locking mechanism's to get, wait for if necessary, and release locks that you define.

    Tom

    Friday, December 10, 2010 6:08 PM
  • Well, this article http://msdn.microsoft.com/en-us/library/ms178104.aspx seems to talk about it.

    BTW, you have a nice collection of the Interview Questions. I got coalesce vs ISNULL and UNION/vs UNION ALL question a while back in one of the interviews.


    Premature optimization is the root of all evil in programming. (c) by Donald Knuth

    Naomi Nosonovsky, Sr. Programmer-Analyst

    My blog
    Friday, December 10, 2010 6:11 PM
    Moderator

All replies

  • The only use of "mutex" that I know of is for a mechanism for re-entrant code that can't be simultaneously executed by multiple processes to force that code to be single threaded.  It's not a typical SQL Server term.  If it were, it would apply as much to stored procedures as triggers.  Generally, in a well designed database with well written code, this would be handled by using standard data locking and transactions.

    If there was some reason, you needed to do this in SQL with something other than data locking, you could use sp_getapplock and sp_releaseapplock to get a hook into the SQL Server locking mechanism's to get, wait for if necessary, and release locks that you define.

    Tom

    Friday, December 10, 2010 6:08 PM
  • Well, this article http://msdn.microsoft.com/en-us/library/ms178104.aspx seems to talk about it.

    BTW, you have a nice collection of the Interview Questions. I got coalesce vs ISNULL and UNION/vs UNION ALL question a while back in one of the interviews.


    Premature optimization is the root of all evil in programming. (c) by Donald Knuth

    Naomi Nosonovsky, Sr. Programmer-Analyst

    My blog
    Friday, December 10, 2010 6:11 PM
    Moderator