There is a DROP INDEX command;
DROP INDEX table_name.index_name
Should work.
It's also possible to disable the index. The pros and cons are discussed here, but the effective point from this article is:
The biggest difference between disabling and dropping an index is whether the metadata and statistics are persisted. If disabled, they are. If dropped, they are not. Make sure you carefully weigh your options before performing either action, and always have a way to recreate the index available.
So in this instance you may want to simply disable the index, collect your stats, then re-enable the index, via:
Disable:
ALTER INDEX index_name ON schema.table_name DISABLE
Enable:
ALTER INDEX index_name ON schema.table_name REBUILD
Answer from dash on Stack OverflowThere is a DROP INDEX command;
DROP INDEX table_name.index_name
Should work.
It's also possible to disable the index. The pros and cons are discussed here, but the effective point from this article is:
The biggest difference between disabling and dropping an index is whether the metadata and statistics are persisted. If disabled, they are. If dropped, they are not. Make sure you carefully weigh your options before performing either action, and always have a way to recreate the index available.
So in this instance you may want to simply disable the index, collect your stats, then re-enable the index, via:
Disable:
ALTER INDEX index_name ON schema.table_name DISABLE
Enable:
ALTER INDEX index_name ON schema.table_name REBUILD
USE [Database_Name_here]
GO
DROP INDEX [<The_Index_Name>]
ON [Schema_Name].[<Table_Name>]
GO
After running it, you can cross check in the object explorer tree, go to that table in object explorer at left, Then check Indexes folder, that index wouldn't be visible after dropping.
HOW TO DROP UNIQUE NON CLUSTERED INDEX – SQLServerCentral Forums
sql server - Adding a Clustered index, should I drop the nonclustered indexes - Database Administrators Stack Exchange
sql server - Dropping a unique clustered index on identity colum - Database Administrators Stack Exchange
sql server - Not able to drop non-clustered index - Database Administrators Stack Exchange
leave it alone
In most OLTP workloads, the primary key is a surrogate key. This isn't a bad thing, especially because someone came along and decided that GUIDs are the best way to uniquely identify various entities in your application. Sure, I get it, it's hard to run out of GUIDs, but that's about where their helpfulness ends.
Even if you were using integer or big integers to uniquely identify entities, there's a strong chance that an identity column would be in use to assign them. As an example, every table in the Stack Overflow database has a clustered primary key on an identity column, and those values are used to identify:
- Users who posted questions
- Users who voted
- Posts that were voted on
- Posts that were commented on
- Comments that will be deleted because comments were a mistake
There's absolutely nothing wrong with surrogate keys, as long as you have sufficient (unique) indexes on the GUID columns that queries will be performing their lookups via.
Having a clustered primary key on an integer or big integer column buys you a few things that using GUIDs does not:
- Narrow data type (4-8 bytes)
- Uniqueness
- Monotonically increasing
- Non-updated data (insert/delete only)
One of the more important parts -- monotonically increasing -- is often not an attribute when GUIDs are used, because they're usually randomly generated. Very few application developers have the foresight to use NEWSEQUENTIALID() to assign GUIDs in the database, and instead generate them in the application, or just by using NEWID() in the database.
For OLTP workloads, having a clustered index (particularly one that meets the criteria I listed above) is far superior to not having one. Tables without clustered indexes (Heaps) in SQL Server can behave in unexpected ways when updated, or deleted from. If you're interested in this, look up forwarded records, and empty allocated pages in this context.
If you were to use non-sequential GUIDs for a clustered index, you would be making random inserts and doing a lot of data page reshuffling, and logging of that reshuffling. It may not matter when a database is small, but it could certainly start to get annoying for larger tables and indexes.
A common scenario for SQL Server is to have a surrogate unique clustered index on an integer or big integer column, and a non-clustered primary key on the GUID column(s) that make up a unique row. That's what you have currently, so don't worry about changing your tables to suit a different arrangement. Instead, just create unique indexes on your GUID columns where queries will use them. One reason for that arrangement is that clustered index key column(s) are automatically added to non-clustered indexes -- as a key when not unique, and as an include when unique -- so the narrow clustered index is more ideal.
In short, leave it alone. You are barking up the wrong tree for optimizing anything whatsoever about your workload.
Clustered indexes and heaps are the base table, where all data is stored. Clustered indexes have the data stored ordered by the cluster key while heaps are generally ordered by their insert order. Nonclustered indexes are a separate beast. But adding or changing a clustered index will require a full rebuild (basically pick up the entire table and put it down again in the new order).
The clustered index (which does not have to be the primary key) determines the order in which rows are stored. If the GUID is randomly generated (i.e. NOT sequential) then it will prove to be a bad cluster key (and not just because of it's datasize). Ideally the cluster key is eternally incrementing.
Personally, given what I know of the table so far, I would have done the same thing, used an integer (or bigint) as the cluster key as a decent compromise and then index the heck out of the GUID or business keys using non-clustered indexes.
Another caveat about heaps is that when records are deleted that the space is not made available to the engine until the heap is rebuilt. This may or may not be of significant concern to you, but is something to keep in mind.
My Advice?
Given that your primary key is a GUID and it's unlikely to be sequential is to leave this as is. The clustered index doesn't take up any more space than a heap and will under most circumstances give you cleaner execution plans than a heap OR the alternative of making the GUID the clustered key.
Storage is cheap and unless you are far outside the curve on I/O and data access patterns you are unlikely to see performance issues around simply having lots of indexes; and I wouldn't start cleanup here, take a look at the other indexes and see if they can be consolidated if you are concerned about that.