简体   繁体   English

提高SQL Server插入查询性能

[英]Improve SQL Server insert query performance

I have a main table with millions of records with huge amounts of data. 我有一个主表,其中包含数百万条包含大量数据的记录。 I regularly insert 300 records into the main table from temp table. 我定期将300条记录从temp表插入到主表中。

Every time I clear the temp table and insert newly created 300 records into the temp table. 每次我清除临时表并将新创建的300条记录插入到临时表中。 Sometimes the insert query is taking more than 10 seconds to insert into main table. 有时,插入查询要花费10秒钟以上的时间才能插入主表。 How can we improve this performance? 我们如何改善这一性能?

INSERT INTO MAINTABLE (COL1, COL2, COL3)
    SELECT COL1, COL2, COL3 
    FROM #TEMP

Temp tables are Created in Tempdb Database , they create additional overhead for SQL Server, slowing overall performance. 临时表是在Tempdb数据库中创建的,它们为SQL Server创建了额外的开销,从而降低了整体性能。

One Another Option is that.....if You are using Temp Table ...then..try to avoid transaction....sometime it's make your query performance slow(Depending on your Data Capcity..). 另一种选择是.....如果您使用的是临时表...然后..以避免事务....有时会使查询性能变慢(取决于您的数据容量)。

Instead you can use Table variables...Table variables are accessible only within the session that created them. 相反,您可以使用表变量...表变量只能在创建它们的会话中访问。

Note:-- There is no Limit for define the size of table variables because it Depends on Memory Size.. 注意:-定义表变量的大小没有限制,因为它取决于内存大小。

Maximum Capicity of Table Variable 表变量的最大容量

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

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