I am writing a DB upgrade script that will check to see if an index has the right two columns defined. If it doesn't, or if it only has one of them, then I will DROP it (is there a way to ALTER an index?) and then recreate it with both.
Sql – clean T-SQL query I can use to verify an index has the right columns
- Sql-server – Does a foreign key automatically create an index
- Sql-server – the best way to auto-generate INSERT statements for a SQL Server table
- Sql-server – Why use the INCLUDE clause when creating an index
- Sql – Selecting COUNT(*) with DISTINCT
- Sql – How to Join to first row
- Sql – How to check if a stored procedure exists before creating it
- Sql – combination of “LIKE” and “IN” in SQL
- Sql – Get top 1 row of each group
I don't have a database immediately on-hand to test this, but you should be able to see if a column exists in an index by using the following IF EXISTS statement.
I'm not sure whether you can alter an index on the fly.