Answer the question
In order to leave comments, you need to log in
How to replace the cursor when inserting data into a table?
Good afternoon.
On MS SQL Server there is a plate, in it the data of the form
ID Parent Value
1 1 2.7
2 1 2.8
3 2 3.2
4 2 3.2
5 2 3.3
6 3 4.1
Parent Lost
1 1
2 0
3 2
Answer the question
In order to leave comments, you need to log in
Well, in some cases, it can be useful to replace the cursor with while, and while with something like insert from select or update "batch"
when there is a problem with volumes and there are prerequisites - then you can bulk insert and / or openrowset
, moreover, 10 inserts in 1 row slower than one insert 10 lines, and bulk is many times faster ... (recently played on a beech - something like a price list - almost a million lines ~ 5-7 sec). That is, in a particularly difficult situation, it may even be acceptable to chain sql-> csv-> bulk
If suddenly anyone is interested:
the cursors are replaced by the following bunch - MSSQL select calculates the shortage table, then the c# application builds csv on this table (repeating the rows the required number of times), and then bulk insert drags it into the database (thanks, d-stream ).
The performance of a particular block has not yet been calculated, but the total processing time has dropped from six and a half hours to an hour and forty only due to the cursor.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question