Replies: 1 comment 6 replies
-
@kwein123 There are a couple of options to do this and a lot depends upon where the data is originating from and what SQL provider you are using. However, some basic considerations for performance. Leverage transactions. #this will always be faster than
Start-SqlTransaction
Invoke-SqlUpdate -Query $insertQuery -Parameters $queryParams #first insert
Invoke-SqlUpdate -Query $insertQuery -Parameters $queryParams #second insert
Invoke-SqlUpdate -Query $insertQuery -Parameters $queryParams #third insert
# ... a bunch more
Invoke-SqlUpdate -Query $insertQuery -Parameters $queryParams #1000th insert
Complete-SqlTransaction
#this will always be slower than the above
Invoke-SqlUpdate -Query $insertQuery -Parameters $queryParams #first insert
Invoke-SqlUpdate -Query $insertQuery -Parameters $queryParams #second insert
Invoke-SqlUpdate -Query $insertQuery -Parameters $queryParams #third insert
# ... a bunch more
Invoke-SqlUpdate -Query $insertQuery -Parameters $queryParams #1000th insert However, there are other things you can do to improve this as well. I'm assuming the data you have to insert has to be gathered somehow. Well, you can always use the SQLite provider to create a local copy of that data in the relational format. So create a SQLite database (just open a connection by passing a filepath, DB will be automatically created if the file doesn't exist), create a table that matches your destination table. Then, insert data into the SQLite database (again -- use transactions). Once that is complete, then open a connection to your destination database (provide a ConnectionName) and then use the You can optimize the above, by copying the SQLite db file across the wan first (make sure to close your SQLite connection before copying the file), and then running the Anyways, if you want to provide more details, I'm happy to brainstorm a bit on how to leverage SimplySql in a performant way. |
Beta Was this translation helpful? Give feedback.
-
I love SimplySql for individual SQL queries. I have an application where I will be uploading millions of records across a WAN as fast as I can. What's the best way to efficiently send, say, 1000 INSERTs at a time, in one batch/transaction? I am the only one accessing this table.
Beta Was this translation helpful? Give feedback.
All reactions