Use of the "updlock" hint with update and insert statements

I have inherited some stored procedures and am trying to figure out why the developers decided to use the "updlock" hint on many of the update and insert statements. I have looked around everywhere and have found only one explanation of why "update...with
(updlock)" can be useful, namely when a table has no clustered index:
http://www.sqlnotes.info/2012/10/10/update-with-updlock/ I have found nothing yet that mentions why "insert into...with (updlock)" might be used. I understand why the hint
might be useful on select statements in some cases, but if all of the tables have clustered indexes, is there any good reason to use it on update and insert statements?
Thanks,
Ron
Ron Rice

This form of deadlock error can occur on a table which has a clustered index.
If you are doing updates on a table which has a clustered index and that table also has a nonclustered index and the nonclustered index is used to find the row to update you can see this type of deadlock.  For example create a table with a clustered
primary key index and a nonclustered index by running
Create Table Foo(PK int primary key identity, OtherKey varchar(10), OtherData int);
go
Insert Foo Default Values;
go 10000
Update Foo Set OtherKey = 'C' + Cast(PK As varchar(10))
Create Unique Index FooIdx On Foo(OtherKey);
That creates a table with 10000 rows, a clustered index and a nonclustered index.  Then run
Begin Transaction
Update Foo Set OtherData = 1 Where OtherKey = 'C5'
That will use the FooIdx index to find the row that needs to be updated.  It will get a U lock on the index row in the FooIdx index, then an X lock on the row in the clustered index, update that row, then free the U lock on FooIdx, but keep the X lock
on the row in the clustered index.  (There is other locking going on, but to simplify things, I'm only showing the locks that lead to the deadlock).
Then in another window, run
Begin Transaction
Update Foo Set OtherData = 2 Where OtherKey = 'C5'
This will get a U lock on the index row in the FooIdx index, then try to get an X lock on the row in the clustered index.  But that row is already exclusively locked, so this second window will wait holding a U lock on FooIdx row and is waiting for
an X lock on the clustered index row.
Now go back to the first window and run
Update Foo Set OtherData = 3 Where OtherKey = 'C5'
This will once again try to get the U lock on the FooIdx row, but it is blocked by the U lock the second window holds.  Of course the second window is blocked by the X lock on the clustered index row and you have a deadlock.
All that said, I certainly do not routinely code my updates with UPDLOCK.  I try to design databases and write code so that deadlocks will be rare without holding excessive locks.  The more locks you hold and the longer you hold them, the more
blocking you will get and the slower your system will run.  So I write code that if a deadlock exception occurs, it is properly handled.  Then if too many deadlocks occur, that is the time to go back to the code to see what changes are needed to
decrease the number of deadlocks (one way to do that may be to get locks earlier and/or hold them longer. 
But I wouldn't worry much about this form of deadlock.  It is, in my experience, vary rare.  I don't recall ever seeing it in a production environment.
Tom

Similar Messages

  • Uses for the Action Property with SQL and Oracle DB Adapters

    This thread is a complement to the Wiki Article
    BizTalk: Streamlining WCF SQL and Oracle Messaging-Only and Other Patterns
    The question.  In what circumstances is explicitly setting the Action value with the WCF SQL and Oracle DB bindings useful or beneficial. 
    A complimentary question.  Is it even possible to set the Action value to anything other than exactly what is required by the Message.
    I ask because of three very specific behaviors of the bindings themselves:
    The binding enforces a match between the Action and the Message, therefore...
    There is a one-to-one relationship between the Message and Action, but...
    The binding is able to correctly derive and perform the requested operation with the unspecific CompositeOperation.
    For clarity, I understand how to set the Action. I. understand what the Action represents in the SOAP scheme. I understand how Action can be used as an abstraction for SOAP operations.
    Thoughts?

    Do you have any good suggestion to learn how to use action property with SQL and Oracle DB adapters?  I learn a lot from your replies for years in BizTalk forum. :)

  • Mutilple updations and insertions by BAPI_SALESORDER_CHANGE at one time

    Hi ,
    I just want to know whether it is possible to insert and update multiple line items in a sales order through the BAPI BAPI_SALESORDER_CHANGE .
    we tried doin it for single record ( update and insert ) , it is working fine . but when we try for mutiple items , it gives a system dump.
    could you plz help out , how to pass the parameters for mutiple updation and insertions at a time?

    HI ALL,
    I THINK IF WE MAKE THE SCHEDULE LINE ITEM NO. TO BE UNIQUE FOR EACH LINE ITEM IT GETS UPLOADED PROPERLY. THE VBEP-ETENR IS 001 ONLY. PEOPLE WITH ALTERNAT ANSWERS PLZ. CORRECT.
    SEE CODES BELOW.
    **This creates additional line no. in the sales order.
    **Material no is hard coded, you need to change the materisl no in
    **available in ur system.
    T_ITEM-itm_number = ''.
    T_ITEM-material = 'AGA350'.
    T_ITEM-target_qty = '2'.
    APPEND T_ITEM.
    T_ITEMx-itm_number = ''.
    T_ITEMX-UPDATEFLAG = 'I'.
    T_ITEMX-target_qty = 'X'.
    T_ITEMX-material = 'X'.
    APPEND T_ITEMX.
    T_SCHE-SCHED_LINE = '1'.
    T_SCHE-REQ_QTY = 2.
    t_sche-req_date = '20080204'.
    APPEND T_SCHE.
    T_SCHEX-updateflag =  c_insertflag.
    t_schex-req_date = 'X'.
    T_SCHEX-SCHED_LINE = '1'.
    t_schex-req_qty = 'X'.
    APPEND T_SCHEX.
    **This also creates additional line no. in the sales order.
    **Material no is hard coded, you need to change the materisl no in
    **available in ur system.
    *T_ITEM-itm_number = ''.
    T_ITEM-material = 'AGA350'.
    T_ITEM-target_qty = '1'.
    APPEND T_ITEM.
    *T_ITEMx-itm_number = ''.
    T_ITEMX-UPDATEFLAG = 'I'.
    T_ITEMX-target_qty = 'X'.
    T_ITEMX-material = 'X'.
    APPEND T_ITEMX.
    T_SCHE-SCHED_LINE = '4'.
    t_sche-req_date = '20080202'.
    T_SCHE-REQ_QTY = 1.
    APPEND T_SCHE.
    T_SCHEX-updateflag =  c_insertflag.
    t_schex-req_date = 'X'.
    T_SCHEX-ITM_NUMBER = 'X'.
    T_SCHEX-SCHED_LINE = '4'.
    T_SCHEX-REQ_QTY = 'X'.
    APPEND T_SCHEX.
    **This also creates additional line no. in the sales order.
    **Material no is hard coded, you need to change the materisl no in
    **available in ur system.
    *T_ITEM-itm_number = ''.
    T_ITEM-material = 'AGA350'.
    T_ITEM-target_qty = '1'.
    APPEND T_ITEM.
    *T_ITEMx-itm_number = ''.
    T_ITEMX-UPDATEFLAG = 'I'.
    T_ITEMX-target_qty = 'X'.
    T_ITEMX-material = 'X'.
    APPEND T_ITEMX.
    T_SCHE-SCHED_LINE = '5'.
    t_sche-req_date = '20080202'.
    T_SCHE-REQ_QTY = 1.
    APPEND T_SCHE.
    T_SCHEX-updateflag =  c_insertflag.
    t_schex-req_date = 'X'.
    T_SCHEX-ITM_NUMBER = 'X'.
    T_SCHEX-SCHED_LINE = '5'.
    T_SCHEX-REQ_QTY = 'X'.
    APPEND T_SCHEX.
    **This also creates additional line no. in the sales order.
    **Material no is hard coded, you need to change the materisl no in
    **available in ur system.
    *T_ITEM-itm_number = ''.
    T_ITEM-material = 'AGA350'.
    T_ITEM-target_qty = '1'.
    APPEND T_ITEM.
    *T_ITEMx-itm_number = ''.
    T_ITEMX-UPDATEFLAG = 'I'.
    T_ITEMX-target_qty = 'X'.
    T_ITEMX-material = 'X'.
    APPEND T_ITEMX.
    T_SCHE-SCHED_LINE = '6'.
    t_sche-req_date = '20080202'.
    T_SCHE-REQ_QTY = 1.
    APPEND T_SCHE.
    T_SCHEX-updateflag =  c_insertflag.
    t_schex-req_date = 'X'.
    T_SCHEX-ITM_NUMBER = 'X'.
    T_SCHEX-SCHED_LINE = '6'.
    T_SCHEX-REQ_QTY = 'X'.
    APPEND T_SCHEX.
    *i_order_header_in-sd_doc_cat

  • I had itunes years ago but the email address associated with this is not longer in use. Is there anyway to updating and transferring all music and data to a new email address?

    I had itunes years ago but the email address associated with this is not longer in use. Is there anyway to updating and transferring all music and data to a new email address?

    Hello Graceevelyn23,
    Thanks for the question, and welcome to Apple Support Communities. You can update the primary email address that is used for your Apple ID:
    Apple ID: Changing the email address you use for your Apple ID
    http://support.apple.com/kb/HT5621
    Thanks,
    Matt M.

  • HT204409 I am unable to connect to my Wi-Fi at home, but am able to connect at work.  Using my new iPad 4G with cellular and a Motorola SBG6580.  My iPad 3G Wi-Fi only connects just fine; the 4G just "spins the gear."

    I am unable to connect to my Wi-Fi at home, but am able to connect at work.  Using my new iPad 4G with cellular and a Motorola SBG6580.  My iPad 3G Wi-Fi only connects just fine; the 4G just "spins the gear."

    Some things to try first:
    1. Turn Off your iPad. Then turn Off (disconnect power cord for 30 seconds or longer) the wireless router & then back On. Now boot your iPad. Hopefully it will see the WiFi.
    2. Go to Settings>Wi-Fi and turn Off. Then while at Settings>Wi-Fi, turn back On and chose a Network.
    3. Change the channel on your wireless router (Auto or Channel 6 is best). Instructions at http://macintoshhowto.com/advanced/how-to-get-a-good-range-on-your-wireless-netw ork.html
    4. Go into your router security settings and change from WEP to WPA with AES.
    5.  Renew IP Address: (especially if you are droping internet connection)
        •    Launch Settings app
        •    Tap on Wi-Fi
        •    Tap on the blue arrow of the Wi-Fi network that you connect to from the list
        •    In the window that opens, tap on the Renew Lease button
    ~~~~~~~~~~~~~~~~~~~~~~~~~
    iOS 6 Wifi Problems/Fixes
    Fix For iOS 6 WiFi Problems?
    http://tabletcrunch.com/2012/09/27/fix-ios-6-wifi-problems/
    Did iOS 6 Screw Your Wi-Fi? Here’s How to Fix It
    http://gizmodo.com/5944761/does-ios-6-have-a-wi+fi-bug
    How To Fix Wi-Fi Connectivity Issue After Upgrading To iOS 6
    http://www.iphonehacks.com/2012/09/fix-wi-fi-connectivity-issue-after-upgrading- to-ios-6.html
    iOS 6 iPad 3 wi-fi "connection fix" for netgear router
    http://www.youtube.com/watch?v=XsWS4ha-dn0
    Apple's iOS 6 Wi-Fi problems
    http://www.zdnet.com/apples-ios-6-wi-fi-problems-linger-on-7000004799/
    ~~~~~~~~~~~~~~~~~~~~~~~
    Look at iOS Troubleshooting Wi-Fi networks and connections  http://support.apple.com/kb/TS1398
    iPad: Issues connecting to Wi-Fi networks  http://support.apple.com/kb/ts3304
    WiFi Connecting/Troubleshooting http://www.apple.com/support/ipad/wifi/
    How to Fix: My iPad Won't Connect to WiFi
    http://ipad.about.com/od/iPad_Troubleshooting/ss/How-To-Fix-My-Ipad-Wont-Connect -To-Wi-Fi.htm
    iOS: Connecting to the Internet http://support.apple.com/kb/HT1695
    iOS: Recommended settings for Wi-Fi routers and access points  http://support.apple.com/kb/HT4199
    How to Quickly Fix iPad 3 Wi-Fi Reception Problems
    http://osxdaily.com/2012/03/21/fix-new-ipad-3-wi-fi-reception-problems/
    iPad Wi-Fi Problems: Comprehensive List of Fixes
    http://appletoolbox.com/2010/04/ipad-wi-fi-problems-comprehensive-list-of-fixes/
    Fix iPad Wifi Connection and Signal Issues  http://www.youtube.com/watch?v=uwWtIG5jUxE
    Fix Slow WiFi Issue https://discussions.apple.com/thread/2398063?start=60&tstart=0
    How To Fix iPhone, iPad, iPod Touch Wi-Fi Connectivity Issue http://tinyurl.com/7nvxbmz
    Unable to Connect After iOS Update - saw this solution on another post.
    https://discussions.apple.com/thread/4010130
    Note - When troubleshooting wifi connection problems, don't hold your iPad by hand. There have been a few reports that holding the iPad by hand, seems to attenuate the wifi signal.
    ~~~~~~~~~~~~~~~
    If any of the above solutions work, please post back what solved your problem. It will help others with the same problem.
     Cheers, Tom

  • When i go to the app store to update the one app that needs to be updated, the screen is blank.  It used to list all the apps that need updating and have a button called update all.  Now nothing.  Just a blank screen.

    when i go to the app store to update the one app that needs to be updated, the screen is blank.  It used to list all the apps that need updating and have a button called update all.  Now nothing.  Just a blank screen.  How can I fix this?

    There's been a problem with this all day.  Seems to be a server problem  -  wait a day and try again, or use itunes on the computer to update, that works.

  • HT1349 I can not run the scanner in my main user, but only the second user and the same thing with updating apps! Why is this happening???

    I can not run the scanner in my main user, but only the second user and the same thing with updating apps! Why is this happening???

    Welcome to the Apple Community.
    Enter the details of her second account at system preferences> mail, contacts & calendars.

  • I lost my Iphone 3GS. My brother has given me his Iphone 4 now. We both use the same notebook to update and sync our phones. I would like to know how can i reconnect back to my account using the Iphone which was previous used by my brother.

    I lost my Iphone 3GS. My brother has given me his Iphone 4 now. We both use the same notebook to update and sync our phones. I would like to know how can i reconnect back to my account using the Iphone which was previous used by my brother.

    If you are saying that you both have iCloud accounts and use the same icloud ID, then yes, the contacts will be deleted.  The idea is that all devices using the same icloud ID are kept in sync.  You need to use different IDs.  You can keep the same iTunes ID so you can share the songs and apps.  But use different icloud IDs.

  • Is there any way to darken the gridlines in iCal?  I'm using it on a Macbook with Lion and find it difficult to see the gridlines on the iCal display.

    Is there any way to darken the gridlines in iCal?  I'm using it on a Macbook with Lion and find it difficult to see the gridlines on the iCal display.

    ''Problem:'' For whatever reason, NoScript is stopping Runescape Community Toolbar from working properly which freezes your first Firefox window.
    ''Fix:'' Uninstall the toolbar. Disable NoScript. Install the toolbar. Add your RS account to it and make sure it works, then Enable NoScript again.
    EDIT: Posted a fix earlier that was wrong. Corrected to the right one, sorry ^_^ Answer was on Runescape Forums.

  • It´s possible to use the "Remote" app with Itunes and a Nokia E72 with Joikuspot installed only? Or I´ll need to buy a modem Wifi?

    It´s possible to use the "Remote" app with Itunes and a Nokia E72 with Joikuspot installed only? Or I´ll need to buy a modem Wifi?
    I was using "remote" with a D-link modem, that works fine at my iPad. But now I´m using only the cell phone as modem 3G, and don´t want to intall a router to put new cables at my notebook.

    What?
    You want to control iTunes on your computer using the Remote app on your iPad?
    And you want to connect the iPad and computer through your Nokia?
    No, this will not work.
    Just create a network with your notebook.

  • HT1369 Ipod touch not being recognized by itunes (but is registering as an external drive by the computer itself) have updated and reinstalled itunes, stopped/started apple mobile device and removed and mobile programs associated with my non apple cellpho

    Ipod touch not being recognized by itunes (but is registering as an external drive by the computer itself) have updated and reinstalled itunes, stopped/started apple mobile device and removed any mobile programs associated with my non apple cellphone. This seems to have started happening after the last Itunes update I did as I was able to put music on my ipod touch a month or so ago. Is there some way to go back to an older version of itunes? I really have no idea what else to do since I followed every step on the trouble shooting page for windows 8.

    I had this problem too and my roommate solved it!
    Go to 'Settings'
    'Music'
    Scroll to the bottom and enter your password to log onto your home sharing
    Then connect to iTunes and sync!

  • How to update and insert the records without using Table_comparison and Map_operation?

    How to update and insert the records without using Table_comparison and Map_operation?

    Use either join or MERGE see this Inserting, Updating, and Deleting Data by Using MERGE

  • I did the 8.0.2 update and no longer have my speak to text microphone down by the smileys.  Don't want to use audio text.  How can I get this back?

    I did the 8.0.2 update and no longer have my speak to text microphone down by the smileys.  Don't want to use audio text.  How can I get this back?

    Hey there tjbliven,
    It sounds like you are not able to use the dictation feature of iOS 8, becuase the microphone icon is missing. It seems to me like Siri may be turned off, which would cause the icon to not be there:
    Siri settings - iPhone
    To set options for Siri, go to Settings > General > Siri. Options include:
    Turning Siri on or off
    That should get the dictation feature back for you.
    Thank you for using Apple Support Communities.
    All the very best,
    Sterling

  • Since most recent OS update, my iMac intel won't open my HP Officejet 4500 scanner. I have un-installed and re-installed the 10.8.3 update and the dame with HP drivers. I get the essage (HP scanner won't open because of a problem". Suggestions???

    Since most recent OS update, my iMac intel won't open my HP Officejet 4500 scanner. I have un-installed and re-installed the 10.8.3 update and the dame with HP drivers. I get the essage (HP scanner won't open because of a problem". The printer works, but not the scanner. Suggestions???

    It's possible that you need new drivers from HP, in order to be compatible with OS X 10.8.3. Looking at HP website, they haven't released new drivers since last November. You might need to wait for new drivers or contact HP to push for an update.
    http://h10025.www1.hp.com/ewfrf/wc/softwareCategory?os=219&lc=en&cc=us&dlc=en&sw _lang=&product=3919448#N218

  • Anybody can help me understand if the Ipads becomes ready to be used in all world regions with 3G and or 4G infrastructure? I mean, are all of them released or when I buy one in the US to be used in Argentina I need to ask for a released one, less cheaper

    anybody can help me understand if the Ipads becomes ready to be used in all world regions with 3G and or 4G infrastructure? I mean, are all of them released or when I buy one in the US to be used in Argentina I need to ask for a released one, with add costs?

    There are two versions of the current iPad, the WiFi only (which will work anywhere in the world, but only connect to WiFi networks) and the 3G/4G model. The latter will connect to 3G networks worldwide, as I understand it, but the only 4G networks it can connect to are in the US and Canada.

Maybe you are looking for