May 22, 2012 at 1:01 pm
Hi all,
I've been trying to find a way to do set-based inserts into a SQL Server.
As near as I can tell, there are only 2 ways:
1) convert the data to be inserted to XML, pass that SQL Server, either a sproc or a file;
2) export to file and BULK INSERT in SQL Server.
Neither of these are especially appealing.
Is there not something equivalent to
$Table.Insert($NewData)
Save-IntoSQLTable appears to be on the right track, but also seems to want only to work with traces.
Any ideas?
May 22, 2012 at 1:59 pm
Anything you can do in .NET you can do in PoSH. Lookup Table-valued Parameters, and how to use them to insert sets of data using one in a Stored Procedure. Most if not all of the examples will be in C# or VB.net, but like I said, you can port that code to PoSH. TVPs or the .NET class SqlBulkCopy are the two best ways I know of to insert batches of data from memory directly into SQL Server. If you write the data to disk that opens up all the bulk load methods of course, like bcp, BULK INSERT, SSIS, etc.
There are no special teachers of virtue, because virtue is taught by the whole community.
--Plato
May 23, 2012 at 8:01 am
Oooooohhh. Me like TVP! 😀
Thanks opc!
July 4, 2012 at 5:45 am
USe Chad Miller´s Out-DataTable and Write-DataTable
it use Bulk Insert.
July 4, 2012 at 6:05 am
Thanks Laerte!
Found you a couple of months ago, I appreciate your work.
I also found these functions last week.
P
July 4, 2012 at 6:07 am
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply