Microsoft Knowledge Base Article
This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved.
Terms
of Use |
Trademarks
The identity column of the destination table does not contain the same identity values as the source table after you use SQL Server Management Studio to import data or to export data in Microsoft SQL Server 2005
| Article ID | : | 952111 |
| Last Review | : | May 5, 2008 |
| Revision | : | 1.0 |
SYMPTOMS
Consider the following scenario:
| • | In Microsoft SQL Server 2005, you use SQL Server Management Studio to import data or to export data from a source table to a destination table. |
| • | Both the source table and the destination table include an identity column. |
| • | You enable the Enable identity insert option for the source table. |
| • | In the SQL Server Import and Export Wizard, you enable the Optimize for many tables option. |
In this scenario, after you finish importing or exporting the data, you find that the identity column of the destination table does not contain the same identity values as the source table. Instead, the identity column of the destination table contains resequenced identity values.
Note This problem does not occur in Microsoft SQL Server 2000.
Back to the top
CAUSE
This problem occurs because the SQL Server Import and Export Wizard does not set the IDENTITY_INSERT property for the table if the
Optimize for many tables option is enabled. The IDENTITY_INSERT property can be set for only one table at a time. If you enable the
Optimize for many tables option in the wizard, the copy operation is performed for several tables on several threads at the same time. Therefore, the SQL Server Import and Export Wizard does not set the IDENTITY_INSERT property.
Back to the top
RESOLUTION
To resolve this problem, do not enable the
Optimize for many tables option in the SQL Server Import and Export Wizard.
If you do not enable the
Optimize for many tables option, the data operation may take a longer time to finish. If you want to preserve the identity values when you import or export a large amount of data, we recommend that you use one of the following methods:
| • | Use the bcp utility together with the –E switch to transfer the table.
For example, first run a command that resembles the following command to export data from the source table to a .txt file:Bcp.exe SourceTable out C:\FileName.txt -S. -T -c –E Then, run a command that resembles the following command to import data to the destination table:Bcp.exe DestinationTable in C:\FileName.txt -S. -T -c -E |
| • | Detach the database, and then attach the database to the destination server. |
Back to the top
MORE INFORMATION
If you enable the
Enable identity insert option for the source table, the SQL Server Import and Export Wizard should execute the SET IDENTITY_INSERT ON statement for each table that contains an identity column. Then, after the identity values are inserted to the destination table, the SQL Server Import and Export Wizard should execute the SET IDENTITY_INSERT OFF statement. However, these operations do not occur correctly if the
Optimize for many tables option is enabled.
Back to the top
STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section.
Back to the top
APPLIES TO
| • | Microsoft SQL Server 2005 Standard Edition |
| • | Microsoft SQL Server 2005 Developer Edition |
| • | Microsoft SQL Server 2005 Enterprise Edition |
| • | Microsoft SQL Server 2005 Standard X64 Edition |
| • | Microsoft SQL Server 2005 Enterprise X64 Edition |
| • | Microsoft SQL Server 2005 Standard Edition for Itanium-based Systems |
| • | Microsoft SQL Server 2005 Enterprise Edition for Itanium-based Systems |
Back to the top
Community Feedback System
Very often, it takes hours to solve a problem. Very often, you've looked high
and low, and have tried a lot of solutions. When you finally found it, chances
are, it was because someone else helped you. Here's your chance to give back.
Use our community feedback tool to let others know what worked for you and what
didn't.
Please also understand that the community feedback system is not warranted to be
correct, it's simply a system that we've built to let people try and help each
other. If something in a feedback response doesn't make sense to you, or you're
not comfortable making changes that the feedback talks about (like registry
edits), please consult a professional.
Thank you for using kbAlertz.com Feedback System.
-- Scott Cate
Be the first to leave feedback, to help others about this knowledge base
article.
(Optional) Name
(Optional)
Public URL Or Email
Comments
No
HTML -- Text Only Please