I’ve recently been assigned the task of updating a “legacy” database (previously managed by an ex-coworker who left the company a while ago). The new database has the exact same structure as the previous one; the only difference is in the content itself, as this database now has more recent data.
The problem is that the old database has a lot of indexes and statistics that I also have to implement in the newer database and I’m afraid the database creation scripts were lost somewhere along the highway.
Hence, how can I (preferably using transact SQL) recreate the old indexes on the new database?
Cheers guys
In SSMS you can right click on an Index in the object Explorer and click “Script Index As”. You could then run the script against your new database.
EDIT:
If you have a number of Indexes, you can’t script them all in SSMS 2005 very easily. You could look at a script similar to this: http://www.sqlservercentral.com/scripts/Miscellaneous/31893/
Another interesting way could be to use C#, see http://blogs.msdn.com/benjones/archive/2008/08/27/how-can-i-generate-a-t-sql-script-for-just-the-indexes.aspx for an example.