简体   繁体   English

在SQL Server上插入/更新表锁

[英]Insert/Update Table Locks on SQL Server

I have a big table with around 70 columns in SQL Server 2008. A multithreaded .NET application is calling a stored proc on database to insert into / update the table. 我在SQL Server 2008中有一个约有70列的大表。一个多线程.NET应用程序正在数据库上调用存储的proc,以插入/更新表。 Frequency is around 3 times a second. 频率大约是每秒3次。

I have made weekly partitions on table since almost every query has a datetime constraint on the table. 因为几乎每个查询在表上都有datetime约束,所以我对表进行了每周分区。

Sometimes it takes a long time to insert/update the table. 有时需要很长时间才能插入/更新表。 I am suspicious that sometimes INSERTION makes UPDATE wait; 我怀疑有时INSERTION使UPDATE等待。 sometimes UPDATE makes INSERTION wait. 有时UPDATE使INSERTION等待。 Is it possible? 可能吗?

How can I design the table to avoid such locks? 如何设计表以避免此类锁定? Performance is the main issue here. 性能是这里的主要问题。

You're right that you're probably hitting deadlocks causing things to wait. 没错,您可能正在陷入僵局,导致事情等待。 A couple things to check first; 首先要检查几件事;

  1. Are your indexes correct? 您的索引正确吗?
  2. If your DB is in 'Full' recovery mode do you need it? 如果您的数据库处于“完全”恢复模式,是否需要它? Simple recovery really speeds up inserts/updates, but you loose point-in-time restores for backups. 简单的恢复确实可以加快插入/更新的速度,但是您失去了备份的时间点恢复。
  3. Are you likely to have multiple threads writing the same record? 您是否可能有多个线程写同一条记录? If not, NOLOCK might be your friend here, but that would mean your data might be inconsitent for a second or two on occasion. 如果不是这样,NOLOCK可能是您的朋友,但这意味着您的数据有时可能一两秒钟不一致。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM