I'm using SQL Server 2008.
Is it possible to create a script to loop over all tables in a database generating a set of index drop scripts and create scripts separately?
What I have to do is drop al开发者_如何学编程l indexes on a set of databases to run a heavy data load process but then I want to re-enable all the indexes. I don't want to have to go through each table and script an index drop and then index create.
I think what you want to do is here. You don't really need to drop the indexes, just disable them while your load is occurring. This script will allow you to disable the indexes for your load, then re-enable when done, and the beauty is it does it all in one shot for the whole database with a single command.
Yes. Someone's already done it so no need to write a script again... :-)
Drop All Indexes and Stats in one Script
Edit. Oops. To create...
Before you drop them... In SSMS, right-click, generate scripts, etc
You could do it with SMO, take a look at SMO Script Index and FK's on a database
精彩评论