From 12256f2013df6a3bd092beb2c14acc38b91a0273 Mon Sep 17 00:00:00 2001 From: techpilot007 <42351972+techpilot007@users.noreply.github.com> Date: Mon, 13 Aug 2018 11:24:40 -0500 Subject: [PATCH] Update-SQLIndexRunbook.ps1 Addressing table in other schemas Updates for Update-SQLIndexRunbook.ps1 -Increased the the timeout for the execution of the average fragmentation query. We've found that having multiple severely fragmented tables leads to the timeout being reached. -Add another Write-Verbose statement to give feed back on where the script is in it's execution. -Concatenate the schema with the table name so that the script can handle tables with the same name in different schemas. --- Utility/SQL/Update-SQLIndexRunbook.ps1 | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Utility/SQL/Update-SQLIndexRunbook.ps1 b/Utility/SQL/Update-SQLIndexRunbook.ps1 index e94284c..c633123 100644 --- a/Utility/SQL/Update-SQLIndexRunbook.ps1 +++ b/Utility/SQL/Update-SQLIndexRunbook.ps1 @@ -155,9 +155,10 @@ workflow Update-SQLIndexRunbook "@ # Return the tables with their corresponding average fragmentation $Cmd=new-object system.Data.SqlClient.SqlCommand($SQLCommandString, $Conn) - $Cmd.CommandTimeout=120 + $Cmd.CommandTimeout=600 # Execute the SQL command + Write-Verbose ("Fetching Fragmented Table Stats...") $FragmentedTable=New-Object system.Data.DataSet $Da=New-Object system.Data.SqlClient.SqlDataAdapter($Cmd) [void]$Da.fill($FragmentedTable) @@ -165,7 +166,7 @@ workflow Update-SQLIndexRunbook # Get the list of tables with their object ids $SQLCommandString = @" - SELECT t.name AS TableName, t.OBJECT_ID FROM sys.tables t + SELECT '[' + s.name + '].[' + t.name + ']' AS TableName, t.OBJECT_ID FROM sys.tables t inner join sys.schemas s on t.schema_id = s.schema_id "@ $Cmd=new-object system.Data.SqlClient.SqlCommand($SQLCommandString, $Conn) @@ -282,4 +283,4 @@ workflow Update-SQLIndexRunbook } Write-Verbose "Finished Indexing" -} \ No newline at end of file +}