简体   繁体   English

SQL Server插入/更新/删除和选择性能/死锁建议

[英]SQL Server insert/Update/Delete and Select performance/deadlock suggestions

I am faced with a task, where I have to design a web application in .net framework. 我面临着一项任务,我必须在.net框架中设计一个Web应用程序。 In this application users will only (99% of the time) have readonly access as they will just see data ( SELECT ). 在这个应用程序中,用户只能(99%的时间)具有只读访问权限,因为他们只会看到数据( SELECT )。

However the backend database is going to be the beast where every minute there will be records updated / inserted / deleted. 然而,后端数据库将成为每分钟更新/插入/删除记录的野兽。 The projection is that at very minimum there will be about 10 million records added to system in a year, in less than 5 tables collectively. 预测是,在一年内,系统中将有大约1000万条记录添加到系统中,总共少于5个表。

Question/Request 1 : 问题/要求1

As these updates/inserts will happen very frequently (every minute or 2 the latest) I was hoping to get some tips so that when some rows are being changed a select query may not cause a thread deadlock or vice-versa. 由于这些更新/插入将非常频繁地发生(每分钟或最近2次),我希望得到一些提示,以便在更改某些行时,选择查询可能不会导致线程死锁,反之亦然。

Question/Request 2 : 问题/要求2

My calculated guess is that in normal situations, only few hundred records will be inserted every minute 24/7 (and updated / deleted based on some conditions). 我的计算猜测是,在正常情况下,每分钟24/7只会插入几百条记录(并根据某些条件更新/删除)。 If I write a C# tool which will get data from any number of sources (xml, csv or direct from some tables from a remote db, a configuration file or registry setting will dictate which format the data is being imported from) and then do the insert / update / deleted, will this be fast enough and/or will cause deadlock issues? 如果我编写一个C#工具,它将从任意数量的源(xml,csv或直接来自远程数据库的某些表中获取数据,配置文件或注册表设置将决定从哪种格式导入数据)然后执行插入/更新/删除,这是否足够快和/或将导致死锁问题?

I hope my questions are elaborate enough... Please let me know if this is all vague... 我希望我的问题足够详细......如果这一切都含糊不清,请告诉我......

Thanks in advance 提前致谢

I will answer first your question #2: According with the scenario you've described, it will be fast enough. 我将首先回答你的问题#2:根据你所描述的情景,它会足够快。 But remember to issue direct sql commands to the database. 但请记住向数据库发出直接sql命令。 I personally have a very, very, similar scenario and the application runs without any problem, but when a scheduled job executes multiples inserts/deletes with a tool (like nhibernate) deadlocks do occurs. 我个人有一个非常非常类似的场景,应用程序运行没有任何问题,但是当一个预定的作业执行多次插入/删除工具(如nhibernate)时,会发生死锁。 So, again, if prossible, execute direct sql statements. 所以,再次,如果不可能,执行直接的sql语句。

Question #1: You can use "SELECT WITH NOLOCK". 问题#1:您可以使用“SELECT WITH NOLOCK”。

For example: 例如:

SELECT * FROM table_sales WITH (NOLOCK)

It avoids blocks on database. 它避免了数据库上的块。 But you have to remember that you might be reading an outdated info (once again, in the scenario you've described probably it will not be a problem). 但是你必须记住,你可能正在阅读一个过时的信息(再一次,在你描述的场景中可能不会有问题)。

You can also try "READ COMMITTED SNAPSHOT", it was supported since the 2005 version, but for this example I will keep it simple. 您也可以尝试“READ COMMITTED SNAPSHOT”,它自2005版以来就受到支持,但是对于这个例子,我会保持简单。 Search a little about it to decide wich one may be the best choice for you. 搜索一下它可以决定哪一个可能是你的最佳选择。

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

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