从旧数据库到新数据库的处理索引?

时间:2021-01-01 04:17:46

I converted an old sql server database from 2000 to 2005 and forgetten to add old indexes to the new db.

从2000年到2005年,我转换了一个旧的sql server数据库,并将旧的索引添加到新的db中。

is there any way to copy the old indexes to the new db?

有没有办法将旧索引复制到新的db?

any help?

任何帮助吗?

2 个解决方案

#1


3  

You cannot copy indexes from one location to the other. They have to be built at the new location.

不能将索引从一个位置复制到另一个位置。他们必须在新的地点建造。

You can script out all your indexes in the old database, and take them over to the new one.

您可以在旧的数据库中编写所有索引的脚本,并将它们转移到新的数据库中。

Right click on the database and under tasks, choose Generate Scripts. Mark the checkbox for all objects and then in the options, choose to script indexes. Run this script on the new database (it will take a while depending on the size of the tables.

在数据库和任务下右键单击,选择Generate Scripts。为所有对象标记复选框,然后在选项中选择脚本索引。在新的数据库上运行这个脚本(根据表的大小需要一段时间)。

#2


2  

If there aren't too many tables, you could generate a script from SSMS with all the objects and their indexes in it, and then just delete the CREATE TABLE statements, leaving the indexes.

如果没有太多的表,您可以从SSMS生成一个脚本,其中包含所有的对象和它们的索引,然后删除CREATE TABLE语句,留下索引。

If there are a large number of tables you're dealing with, it might be easier to use a tool like Red-Gate's "SQL Compare" or Visual Studio Database Edition to do schema comparison and generate the missing indexes.

如果您正在处理大量的表,那么使用Red-Gate的“SQL比较”或Visual Studio数据库Edition之类的工具进行模式比较并生成缺失的索引可能更容易。

#1


3  

You cannot copy indexes from one location to the other. They have to be built at the new location.

不能将索引从一个位置复制到另一个位置。他们必须在新的地点建造。

You can script out all your indexes in the old database, and take them over to the new one.

您可以在旧的数据库中编写所有索引的脚本,并将它们转移到新的数据库中。

Right click on the database and under tasks, choose Generate Scripts. Mark the checkbox for all objects and then in the options, choose to script indexes. Run this script on the new database (it will take a while depending on the size of the tables.

在数据库和任务下右键单击,选择Generate Scripts。为所有对象标记复选框,然后在选项中选择脚本索引。在新的数据库上运行这个脚本(根据表的大小需要一段时间)。

#2


2  

If there aren't too many tables, you could generate a script from SSMS with all the objects and their indexes in it, and then just delete the CREATE TABLE statements, leaving the indexes.

如果没有太多的表,您可以从SSMS生成一个脚本,其中包含所有的对象和它们的索引,然后删除CREATE TABLE语句,留下索引。

If there are a large number of tables you're dealing with, it might be easier to use a tool like Red-Gate's "SQL Compare" or Visual Studio Database Edition to do schema comparison and generate the missing indexes.

如果您正在处理大量的表,那么使用Red-Gate的“SQL比较”或Visual Studio数据库Edition之类的工具进行模式比较并生成缺失的索引可能更容易。