MS SQL Server Concepts and Programming Question:
Download Job Interview Questions and Answers PDF
How To Recreate an Existing Index in MS SQL Server?
Answer:
If you want to change the definition of an existing index, you can use the "DROP INDEX" statement to drop the index first. Then use the "CREATE INDEX" statement to create it again with the new definition.
But you can also combine those two statements into one:
CREATE INDEX ... WITH (DROP_EXISTING = ON)
The tutorial exercise below recreates ggl_links_url with a change to index columns:
USE GlobalGuideLineDatabase;
GO
CREATE INDEX ggl_links_url ON ggl_links_indexed (url, counts)
WITH (DROP_EXISTING = ON);
GO
SP_HELP ggl_links_indexed;
GO
<pre>index_name index_description index_keys
---------------- -------------------------------- ------------
ggl_links_counts nonclustered located on PRIMARY counts
ggl_links_url nonclustered located on PRIMARY url, counts</pre>
But you can also combine those two statements into one:
CREATE INDEX ... WITH (DROP_EXISTING = ON)
The tutorial exercise below recreates ggl_links_url with a change to index columns:
USE GlobalGuideLineDatabase;
GO
CREATE INDEX ggl_links_url ON ggl_links_indexed (url, counts)
WITH (DROP_EXISTING = ON);
GO
SP_HELP ggl_links_indexed;
GO
<pre>index_name index_description index_keys
---------------- -------------------------------- ------------
ggl_links_counts nonclustered located on PRIMARY counts
ggl_links_url nonclustered located on PRIMARY url, counts</pre>
Download MS SQL Server Interview Questions And Answers
PDF
Previous Question | Next Question |
How To Rebuild All Indexes on a Single Table? | What Are Views in MS SQL Server? |