Skip to main content
Community site session details

Community site session details

Session Id : UXW1a18N+yKLfNWySD6LyS
Power Automate - Building Flows
Answered

Extremely Slow SQL inserts

Like (0) ShareShare
ReportReport
Posted on 14 Apr 2020 12:36:18 by

Hi everyone,

 

I have a flow that takes rows from an Excel table and inserts it into a SQL database in Azure. The inserts into the SQL database are happening but at an extremely slow rate. For 256 rows to be inserted it took 14 minutes to complete. I have a column that sets the time when the record is created and there you can see well that the inserts are very slow. Is there anything that can be done to speed this up? 

 

 

 

Id        CreatedTime
22947 2020-04-14 12:30:33.503
22946 2020-04-14 12:30:32.587
22945 2020-04-14 12:30:31.527
22944 2020-04-14 12:30:30.120
22943 2020-04-14 12:30:29.167
22942 2020-04-14 12:30:27.917
22941 2020-04-14 12:30:26.790
22940 2020-04-14 12:30:25.723
22939 2020-04-14 12:30:24.440
22938 2020-04-14 12:30:23.493

 

 

 

 
  • takolota1 Profile Picture
    4,911 Moderator on 28 Aug 2022 at 02:12:16
    Re: Extremely Slow SQL inserts

    You can also try using this batch SQL template:

    https://powerusers.microsoft.com/t5/Power-Automate-Cookbook/SQL-Batch-Create-Read-Update-and-Delete/td-p/1715338

  • bbk Profile Picture
    3 on 28 Jun 2022 at 21:01:12
    Re: Extremely Slow SQL inserts

    Hi JoostPielage,

     

    Could you please let me know how you added Account Name, First Name and Surname? No individual column is available in the output of 'List rows present in a table'.

  • gildsjbrazil Profile Picture
    2 on 24 Oct 2020 at 00:02:35
    Re: Extremely Slow SQL inserts

    Hi, Give an example how is the query in sql to insert the OUTPUT.
    I thought something like :
    INSERT INTO Employee
    SELECT *
    FROM OPENJSON({OUTPUT}

  • Pranshu27 Profile Picture
    5 on 14 Jul 2020 at 07:48:21
    Re: Extremely Slow SQL inserts

    Hey @Anonymous 

    How many rows are you processing?

    I had 5k+ rows so I used a do until loop and a couple of variables, condition logic to process all records.

    I am using execute SQL procedure operation just after compose JSON output. So, it inserts 5k rows per batch. I am incrementing the values using variable SkipCount and using that in advanced properties of Excel Get list by rows. 

    Let me know if you have any questions

  • Community Power Platform Member Profile Picture
    on 14 Jul 2020 at 07:13:07
    Re: Extremely Slow SQL inserts

    Hi @Pranshu27,

    Please let me know once you will post your blog article. I have exactly the same approach as you described - 5k rows portions that take 2 minutes each to load to SQL. Would be great to compare and see if there is still something to improve in my pipeline.

  • Pranshu27 Profile Picture
    5 on 14 Jul 2020 at 06:36:52
    Re: Extremely Slow SQL inserts

    Thanks a lot for this approach. I was able to use this to get desired output. Previously It took me 1 hour to insert 5k rows. Now, I am able to insert 5300 rows within 2 minutes... I am taking the JSON output from Compose and used it as an input to stored procedure which inserts records in the destination table using OPENJSON. I used Variables and do Until loop to process more than 5k rows which is a limitation in MS Flow. I will definitely write a blog about it.

     

  • RichardW Profile Picture
    17 on 13 Jul 2020 at 13:38:37
    Re: Extremely Slow SQL inserts

    Hi @Anonymous ,

     

    Thanks for the examples - really appreciated! I will have a try and see if I can make it work for my flow...thanks again!

     

    Richard

  • Community Power Platform Member Profile Picture
    on 13 Jul 2020 at 10:12:34
    Re: Extremely Slow SQL inserts

    Hi @RichardW ,

     

    I basically store the JSON output from the compose into a SQL temp table. 

     

    INSERT INTO @TheTable SELECT '@{outputs('Compose_5')}'
    SET @JSON = (SELECT TheJSON FROM @TheTable)

     

    After that, you can use the JSON to insert the values into a table. You need to make sure that your column names match up. You can see an example here:

     

    https://stackoverflow.com/questions/46323946/how-to-insert-json-object-to-sql-server-2016-as-nvarchar

     

    If you have any question let me know, I;ll try and help where I can

  • RichardW Profile Picture
    17 on 13 Jul 2020 at 07:14:32
    Re: Extremely Slow SQL inserts

    Hi @Anonymous ,

     

    I am glad I found your topic as I am also struggling to insert 50k+ rows from Excel to SQL Server using flow...Could I ask how do you use Compose output in your SQL query to insert? Do you mind providing a quick example or some documentation as reference? BTW our SQL Server is on-premise so I will probably wrap the query in stored procedure. Thanks for your help in advance!

     

    Richard

  • Community Power Platform Member Profile Picture
    on 01 May 2020 at 17:20:05
    Re: Extremely Slow SQL inserts

    Hi @Anonymous if you go to the settings of you excel step. You can enable pagination and go past the initial 5000 row limit. The ultimate limit is 100k. I have never tested that. I have gone up to 52k without a big issue. Good luck on your flow!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing our 2025 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for…

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Tomac Profile Picture

Tomac 986 Moderator

#2
stampcoin Profile Picture

stampcoin 699 Super User 2025 Season 2

#3
Riyaz_riz11 Profile Picture

Riyaz_riz11 577 Super User 2025 Season 2