简体   繁体   中英

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.

Every time I clear the temp table and insert newly created 300 records into the temp table. Sometimes the insert query is taking more than 10 seconds to insert into main table. 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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