Solved

insert statements and indexes  sql 2012

Posted on 2013-11-01
8
306 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
 

Author Comment

by:al4629740
ID: 39618300
Drop and then recreate after each time?  This could happen a hundred times in a day?  Really?
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
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:
ScottPletcher 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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

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

I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

920 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now