How to delete all indexes from one database, whether clustered or nonclustered?
I need do that with script, not over GUI.
EDITED
Database has 7 tables, some of them are lookups, some are related over foreign keys. Every table has minimal one index, created in time the primary key was created, so automatically was created constraint. When deleting such indexes over an GUI, I got an error that indexes cannot be deleted because of dependency on other keys.
So, I need to first delete an indexes keys that are foreign keys, and then an indexes created over primary keys.
Slightly different variation of dynamic SQL, however it drops foreign keys first, then primary keys, then indexes (non-clustered indexes first so that you don’t convert to a heap (which can affect all the non-clustered indexes)).
First, delete all foreign keys:
Now drop primary keys:
And finally, indexes, non-clustered first:
Note that the database engine tuning advisor will recommend a bunch of these indexes (and depending on the workload you present it, may miss some, and may suggest redundant and nearly duplicate indexes). However it is not going to recommend any of the data integrity stuff you just deleted (PK, FK, unique constraints).