如何导入表而不丢失SQL Server 2008中的索引和键

时间:2022-06-28 01:45:39

When I use import/export wizard it loses keys and indexes. I need to import many tables. please help.

当我使用导入/导出向导时,它会丢失密钥和索引。我需要导入很多表。请帮忙。

Also I created tables by generating script and then do importing, but appear validating error. Maybe I'm doing something wrong?

我也通过生成脚本创建表,然后进行导入,但出现验证错误。也许我做错了什么?

1 个解决方案

#1


5  

First you make a create script to create tables, keys, indexes. If you right click on database, in the context menu you can click create script on database call the wizard.

首先,创建一个创建脚本来创建表,键,索引。如果右键单击数据库,则可以在上下文菜单中单击“在数据库上创建脚本”调用向导。

With this script you can create your new database. Afterwards you import your data as it is, but your SSIS (aka DTS) wizard don't create the table, but just import the data.

使用此脚本,您可以创建新数据库。然后按原样导入数据,但是您的SSIS(又名DTS)向导不会创建表,而只是导入数据。

Remark: If you have FOREIGN KEYS, you need to make sure that your SSIS data import part imports in the right order!

备注:如果您有FOREIGN KEYS,您需要确保您的SSIS数据导入部件按正确的顺序导入!

I went the way myself to make a big sql textfile which creates all structure where each part is seperated by GO and another file where I create the data (this can be replaced by your wizard).

我自己创建了一个大的sql文本文件,它创建了所有结构,其中每个部分由GO和另一个文件分隔,我创建数据(这可以由你的向导替换)。

#1


5  

First you make a create script to create tables, keys, indexes. If you right click on database, in the context menu you can click create script on database call the wizard.

首先,创建一个创建脚本来创建表,键,索引。如果右键单击数据库,则可以在上下文菜单中单击“在数据库上创建脚本”调用向导。

With this script you can create your new database. Afterwards you import your data as it is, but your SSIS (aka DTS) wizard don't create the table, but just import the data.

使用此脚本,您可以创建新数据库。然后按原样导入数据,但是您的SSIS(又名DTS)向导不会创建表,而只是导入数据。

Remark: If you have FOREIGN KEYS, you need to make sure that your SSIS data import part imports in the right order!

备注:如果您有FOREIGN KEYS,您需要确保您的SSIS数据导入部件按正确的顺序导入!

I went the way myself to make a big sql textfile which creates all structure where each part is seperated by GO and another file where I create the data (this can be replaced by your wizard).

我自己创建了一个大的sql文本文件,它创建了所有结构,其中每个部分由GO和另一个文件分隔,我创建数据(这可以由你的向导替换)。