We want to run all stored procedures in parallel. The powershell script finds a list of stored procedures in the database (only have 5 right now), and runs them simultaneously. This code seems to be working. Is there anymore efficient or recommended method to conduct this, or does the code seem valid?
Workflow TestRunParallelExecute
{
$ServerName = "localhost"
$DatabaseName = "testrun"
$Procedure_Query = "select name from sys.procedures"
$Procedure_List = (Invoke-Sqlcmd -Server $ServerName -Database $DatabaseName -Query $Procedure_Query)
ForEach -Parallel ($Procedure in $Procedure_List.Name)
{
Invoke-Sqlcmd -Server $ServerName -Database $DatabaseName -Query $Procedure
}
}
TestRunParallelExecute
cls
I read many resources below, wanted to come up with easy way using Powershell new ForEach -Parallel function.
Run stored procedures in parallel
https://stackoverflow.com/questions/29193805/executing-stored-procedures-in-parallel
https://stackoverflow.com/questions/48803101/run-several-stored-procedure-in-parallel-in-sql-server