Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable and re-enable all indexes in a SQL Server database

I am running a DTS to preform tasks in my database, in which at first I need to disable all indexes in the database and re-enable them when the DTS finish his work.

Is there a way that I can disable all the indexes in the whole database and afterwards to re-enable them all?

I know how to disable/enable one by one, can someone help me with the way to disable/enable all at once as a step in the DTS.

like image 297
Eran Meir Avatar asked Aug 14 '13 15:08

Eran Meir


People also ask

How do I disable and enable indexes in SQL Server?

To enable a disabled indexClick the plus sign to expand the Indexes folder. Right-click the index you want to enable and select Rebuild. In the Rebuild Indexes dialog box, verify that the correct index is in the Indexes to rebuild grid and click OK.

Which of the following query is used to enable a disabled index using create index?

Which of the following query is used to enable a disabled index using CREATE INDEX? Explanation: Enabling a disabled index can be done using SSMS.


1 Answers

We can use below scrip to disable indexes

ALTER INDEX ALL ON [TableName] DISABLE; 

Do your bulk insert to table and than run below script.

ALTER INDEX ALL ON [TableName] REBUILD; 
like image 132
Rahul Garg Avatar answered Oct 21 '22 18:10

Rahul Garg