From the course: Automating SQL Server with dbatools

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Insert data into SQL Server tables

Insert data into SQL Server tables - SQL Server Tutorial

From the course: Automating SQL Server with dbatools

Insert data into SQL Server tables

- [Instructor] As data professionals, we like data in tables. It's a great way of storing information we want to keep track of and quite often in the past, I've found myself generating data in PowerShell from some process and then wishing there was an easy way to just save that into a database table. And now there is, Write-DbaDbTableData will take data we have in a PowerShell object and using SQL bulk copy, will insert it into our database table. For these examples, we're going to be writing data into the database admin database. So, I've set up a hash table with the connection information that we can reuse for splatting. Let's start with a simple example. We've already used Get-DbaDatabase a few times, so we know that it gets information about databases in RSD. I'm selecting just a few properties for now, the name, owner, status, and last full backup time. And then, we'll pipe that into Write-DbaDbDataTable, and…

Contents