Delete an index
We have seen how to add indexes. We also need to be able to remove them
| 001 002 003 004 005 006 007 008 009 010 011 012 013 014 015
| function Remove-AccessIndex { # .ExternalHelp Maml-AccessFunctions.XML [CmdletBinding()] param ( [string]$table, [string]$index, [System.Data.OleDb.OleDbConnection]$connection ) $sql = "DROP INDEX $index ON $table" Write-Debug $sql $cmd = New-Object System.Data.OleDb.OleDbCommand($sql, $connection) $cmd.ExecuteNonQuery() } |
The function accepts connection plus table and index names. Use the function as
remove-accessindex –table test1 –connection $db –index index_name
If you need to remove multiple indexes on a table try
“index1”, “index2”, “index3” | foreach {remove-accessindex –table test1 –connection $db –index $_ }