I need to copy the indexes from one table to another. There are a LOT of indexes and I don't want to recreate them from scratch. Seems error prone anyways.
I have copied the structure using
SELECT * INTO [BackupTable] FROM [OriginalTable]
But that doesn't copy indexes, constraints, triggers etc
Does anyone know how to do this?
Select the DATABASE from which you want to copy the table, then right Click on that and Select the TASK then Select Generate Script. follow it. Step 3. Choose Script Options -> Table/View Options -> Select two indexes option and change both to True.
You can use the sp_helpindex to view all the indexes of one table. And for all the indexes, you can traverse sys. objects to get all the indexes for each table. Only problem with this is that it only includes the index key columns, not the included columns.
Launch SQL Server Management Studio. Select and right-click on the Source Database, go to Tasks > Export Data. Import/Export Wizard will be opened and click on Next to proceed. Enter the data source, server name and select the authentication method and the source database.
Do you want to copy the Index definition?
Then you can reverse engineer the index, triggers etc using the "Script" option in the Microsoft SQL Management tool
Simply right click on a table name in the SQL Management Studio table list and select "Script Table as" and then "Create to"
You can't copy the Index data as it relates to the physical storage of the Index
First check that you have "Tools/Options/SQL Server Object Explorer/Scripting/Script Indexes" set to "True". This is set to false in some version of the SQL Management tool (thanks Mark)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With