数据插入到SQL服务器的最佳性能 [英] Insert data into SQL server with best performance

查看:120
本文介绍了数据插入到SQL服务器的最佳性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有集中使用数据库(SQL Server)的一个程序

由于它必须具备高性能的,我想知道从执行时间的角度插入记录到DB.Fastest的最快方法。

我应该怎么使用?

据我所知最快的方法是创建存储过程,并从code(ADO.NET)调用它。 请让我知道有没有更好的办法,也可以有一些其他的做法,以提高性能。

解决方案
  

请让我知道有没有更好的办法,也可以有一些其他的做法,以提高性能。

  • 请不要打开每个记录一个连接。请学习如何连接池通常阻止你在不经意间打开每个记录一个连接。
  • 如果可能的话,请不要打开每个记录一个事务。另外,不要把事务开放的时间不适当的时间。
  • 在考虑表设计:用几个指标/约束和无触发器窄表
  • 如果你需要一个快速的插入,因为你是一个Web应用程序,需要一个页面现在返回给用户,或者你是一个winform应用程序,并阻塞UI线程上,考虑执行插入异步或在另一个线程
  • 如果您需要一个快速插入导入百万行的文件,可考虑做一个批量插入。
  • 如果你想要做的是存储数据,而不是查询它......考虑使用基于文件的解决方案来代替。

I have an application which intensively uses DB (SQL Server).

As it must have high performance I would like to know the fastest way to insert record into DB.Fastest from the standpoint of execution time.

What should I use ?

As I know the fastest way is to create stored procedure and to call it from code (ADO.NET). Please let me know is there any better way or may be there are is some other practices to increase performance.

解决方案

Please let me know is there any better way or may be there are is some other practices to increase performance.

  • Do not open one connection per record. Do learn how connection pooling generally stops you from inadvertently opening one connection per record.
  • If possible, do not open one transaction per record. Also do not leave the transaction open for undue periods of time.
  • Consider table design: narrow tables with few indexes/constraints and no triggers.
  • If you need a fast insert because you're a web application and need to return a page to the user NOW or you're a winform app and are blocking on the UI thread, consider performing the insert async or on another thread.
  • If you need a fast insert to import a million line file, consider doing a bulk insert.
  • If all you want to do is store the data, and not to query it... consider using a file-based solution instead.

这篇关于数据插入到SQL服务器的最佳性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆