Reputation: 41
I have a homework assignment where I have a nonclustered index. Later on in the assignment, I have to add a filter to the index. Is it possible to add a filter to an existing index?
This is my assignment and the order I have to do them in. In the end they all have to run as a single script.
Create an index following naming conventions on the transaction type column. It is used in ascending order.
Alter the index to have a fill factor of 80. We opt for not keeping the index online, we want full optimization.
We are actually only looking at transactions of type 'W', add a filter to the index.
Drop the index
For #3 do I have to drop the index I created in #1 add a new one with a filter and then drop it again in #4?
Upvotes: 2
Views: 612
Reputation: 46203
For #3 do I have to drop the index I created in #1 add a new one with a filter and then drop it again in #4?
SQL Server allows one to recreate an existing index using the syntax CREATE INDEX...WITH(DROP EXISTING=ON). This method avoids the need to drop the existing index beforehand and improves performance of the index recreate by leveraging the sort order of the original index. The WITH
clause also provides additional options to meet your online requirement. See the documentation link above for details.
Upvotes: 1