Transaction (Process ID ) was deadlocked on lock resources with another process and has been chosen
2011-09-19 12:07
531 查看
You had written update or delete statements without SQL hints like nolock, updlock, readpast etc.
This is very bad practice when you are dealing with multiple udates on rows or tables without locks.
Below scenario will explain how to use those hints to avoid deadlocks aswell as concurrency issues.
e.g.
UPDATE top 10 xyzTable with (updlock)
set x = 1
In this case if second user comes in to update xyzTable, he has to wait for first user operation to finish.
To let second user do update on next top 10 rows which are not locked by first user, you can
modify above query using readpast hint.
ReadPast hint will return row sets which are not locked by any transaction in that contxt.
UPDATE top 10 xyzTable with (updlock,readpast)
set x = 1
ReadPast and NoLock are two different hints
Readpast Only return rows which are not locked, while nolock returns
commited as well as non commited rows by other transaction this is also called as dirty reads.
SP_LOCK will written locks details.
You can avoid concurrency issues with your transaction using those lock hints.
For more information about locks in MS SQL you can visit
http://msdn.microsoft.com/en-us/library/aa213026(SQL.80).aspx
This is very bad practice when you are dealing with multiple udates on rows or tables without locks.
Below scenario will explain how to use those hints to avoid deadlocks aswell as concurrency issues.
e.g.
UPDATE top 10 xyzTable with (updlock)
set x = 1
In this case if second user comes in to update xyzTable, he has to wait for first user operation to finish.
To let second user do update on next top 10 rows which are not locked by first user, you can
modify above query using readpast hint.
ReadPast hint will return row sets which are not locked by any transaction in that contxt.
UPDATE top 10 xyzTable with (updlock,readpast)
set x = 1
ReadPast and NoLock are two different hints
Readpast Only return rows which are not locked, while nolock returns
commited as well as non commited rows by other transaction this is also called as dirty reads.
SP_LOCK will written locks details.
You can avoid concurrency issues with your transaction using those lock hints.
For more information about locks in MS SQL you can visit
http://msdn.microsoft.com/en-us/library/aa213026(SQL.80).aspx
相关文章推荐
- Transaction (Process ID) was deadlocked on lock resources with another process and has been chose
- org.neo4j.kernel.StoreLockException: Store and its lock file has been locked by another process
- 今天生产环境出现 Transaction (Process ID xx) was deadlocked异常
- WebLogic Server (WLS) Hangs With Deadlocked Socket Close() and Poll() Threads on AIX
- Notes: Process in Operation System and Dead Lock 操作系统中的进程和死锁问题
- tomcat 7 WARNING: A context path must either be an empty string or start with a '/' and do not end with a '/'. The path [/] does not meet these criteria and has been changed to []
- We are already in the process of making 11 connections and the number of simultaneous builds has been throttled to 10
- 错误代码:1100 Table 't_depart_info' was not locked with LOCK TABLES的解决方法
- Yii: MySql - Table 'card' was not locked with LOCK TABLES
- WebLogic Server (WLS) Hangs With Deadlocked Socket Close() and Poll() Threads on AIX 【转】
- Proxool抛出的警告 was active for 365172 milliseconds and has been removed automaticaly
- LR场景运行提示:This Vuser already started a transaction with the same name, and has not yet processed the
- Azure 删除VHD时报错:There is currently a lease on the blob and no lease ID was specified in the request
- sharepoint2010 The Ribbon Tab with id: "Ribbon.Read" has not been made
- Proxool抛出的警告 was active for 365172 milliseconds and has been removed automaticaly
- Creating properties on demand (a.k.a. dynamic properties) has been deprecated and is scheduled to be
- Dynamic CRM 2013学习笔记(三十)Linq使用报错 A proxy type with the name account has been defined by another assembly
- Compare PostgreSQL and Oracle dead lock detect and transaction
- The web server process that was being debugged has been terminated by Internet Information Services (IIS).
- has been registered with some other pool, and can not register it again.