From the course: PowerShell for SQL Server Administration

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Inserting data into tables

Inserting data into tables - PowerShell Tutorial

From the course: PowerShell for SQL Server Administration

Start my 1-month free trial

Inserting data into tables

- [Narrator] Once we've got our tables created, next thing we need to do, insert some data. So, like most things, there's a couple different ways we can do this. We can either use SQLPS so we can write data into the table using the new Write-SqlTableData cmdlet that was introduced in PowerShell 5, or we can use Native T-SQL to do the insert. Really depends on what we want to do. Now, if you're using an older version of PowerShell, so you don't have v5 of PowerShell available, then I would have said the Native T-SQL is going to be the right way to go, because writing data to a table through PowerShell would have been extremely complex up through PowerShell v4. Starting with PowerShell v5, however, now we've got the Write-SqlTableData cmdlet that we can use to insert data, and we can do it very, very quickly and easily. So now I'm switching over from T-SQL as the right option more towards the SQL PowerShell might be the way to go with this Write-SqlTableData cmdlet. So let's go ahead…

Contents