SQL Server database to avoid deadlocks

Source: Internet
Author: User

Reduce database deadlocks!

Here are some tips on how to avoid deadlocking on your SQL Server:

  • Ensure the database design is properly normalized.
  • Have the application access server objects in the same order each time.
  • During transactions, don't allow any user input. Collect it before the transaction begins.
  • Avoid cursors.
  • Keep transactions as short as possible. one way to help accomplish this is to reduce the number of round trips between your application and SQL server by using stored procedures or keeping transactions with a single batch. another way of processing the time a transaction takes to complete is to make sure you are not properly Ming the same reads over and over again. if your application does need to read the same data more than once, cache it by storing it in a variable or an array, and then re-reading it from there, not from SQL Server.
  • Reduce lock time. Try to develop your application so that it grabs locks at the latest possible time, and then releases them at the very earliest time.
  • If appropriate, reduce lock escalation by using the rowlock or paglock.
  • Consider using the nolock hint to prevent locking if the data being locked is not modified often.
  • If appropriate, use as low of an isolation level as possible for the user connection running the transaction.
  • Consider using bound connections.

 

Http://www.simple-talk.com/ SQL /learn-sql-server/how-to-track-down-deadlocks-using-sql-server-2005-profiler/

 

 

 

 

SET transaction isolation level
{Read committed
| Read uncommitted
| Repeatable read
| Serializable
}

 

 

Http://msdn.microsoft.com/en-us/library/aa259197 (SQL .80). aspx

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.