Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

insert statements and indexes  sql 2012

Posted on 2013-11-01
8
316 Views
Last Modified: 2013-11-04
I have read that the execution of insert statements in sql slow down when a table has indexes.  Insert statements are regularly used with my rather large table.  Is there a way to index the table and at the same time optimize it so that the insert statements will execute faster?
0
Comment
Question by:al4629740
8 Comments
 
LVL 21

Expert Comment

by:oleggold
ID: 39618295
You could drop the index before insert and recreate after
0
 
LVL 21

Expert Comment

by:oleggold
ID: 39618296
if You use any graphic tool,such as quest toad for mssql free You can generate the table's ddl which will contain "create index" command and then  run it after Your insert is complete
0
 
LVL 21

Expert Comment

by:oleggold
ID: 39618298
i would though verify Your insert doesn't absolutely need any index by checking query execution plan
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:al4629740
ID: 39618300
Drop and then recreate after each time?  This could happen a hundred times in a day?  Really?
0
 
LVL 21

Assisted Solution

by:oleggold
oleggold earned 125 total points
ID: 39618301
sometimes developers construct the dml/inserts based on the data already in the table which means they will run select using the indexes You may need ,after select is complete and insert command generated You can drop the indexes.
0
 
LVL 10

Assisted Solution

by:HuaMinChen
HuaMinChen earned 125 total points
ID: 39618317
You can create Indexed view on the same table to achieve better performance. Read
http://msdn.microsoft.com/en-us/library/ms191432.aspx
0
 
LVL 48

Assisted Solution

by:PortletPaul
PortletPaul earned 125 total points
ID: 39618473
>>Drop and then recreate after each time?
I don't believe that suggestion was made knowing it was needed hundreds of times a day (the assumption may have been you had a particularly large one-off set of inserts to perform for example). re-building the indexes multiple times a day would not be a good idea at all.

It is a trade-off between query speed and insert speed when you create indexes because for each index there are adjustments to the index for each insert.

HuaMinChen has pointed you to indexed views as an alternative strategy. Here you minimize the indexes on the table which is good for inserts, and you now have some indexes moved to the view of that table - however many/most of your queries would now need to use the view and not the table to take advantage of that approach. So there are "costs", or impacts, in all options.
0
 
LVL 69

Accepted Solution

by:
Scott Pletcher earned 125 total points
ID: 39621944
All non-clustered indexes are a trade-off.  Yes, they require maintaining during DELETEs, INSERTs and UPDATEs, and thus slow those statements down somewhat.  But, for indexes that are really needed, it's worth it, because of improved performance in queries.

Still, there are at least two big things you can do to help:
    1) remove underused or unused indexes.  You can use sys.dm_db_index_usage_stats to determine that, but be sure to wait long enough before removing indexes; for example, only one day or two may not be sufficient time for some indexes to determine whether they will be used or not.
    2) use filtered indexes whenever appropriate (filtered indexes are a great feature but are easy to forget/overlook).
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Visual Studios 1 76
LTrim & Double Space Correction 5 39
tempdb log keep growing 7 32
SQL, add where clause 5 23
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

766 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question