insert statements and indexes sql 2012

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?
Who is Participating?
Scott PletcherConnect With a Mentor Senior DBACommented:
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).
You could drop the index before insert and recreate after
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
A proven path to a career in data science

At Springboard, we know how to get you a job in data science. With Springboard’s Data Science Career Track, you’ll master data science  with a curriculum built by industry experts. You’ll work on real projects, and get 1-on-1 mentorship from a data scientist.

i would though verify Your insert doesn't absolutely need any index by checking query execution plan
al4629740Author Commented:
Drop and then recreate after each time?  This could happen a hundred times in a day?  Really?
oleggoldConnect With a Mentor Commented:
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.
HuaMinChenConnect With a Mentor Business AnalystCommented:
You can create Indexed view on the same table to achieve better performance. Read
PortletPaulConnect With a Mentor Commented:
>>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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.