[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

DMO: Identity column trashed by bulk copy

Posted on 1998-10-15
4
Medium Priority
?
338 Views
Last Modified: 2008-01-09
I'm using the SQL-DMO BulkCopy object in VB 5 to transfer data between servers. It is important to maintain the existing identity values since they are referenced by other tables, so I set the BulkCopy.IncludeIdentityValues property to "true" on both the export and import sides, but the identity values are regenerated by SQL Server nonetheless when the import is done.  I also tried running the "set tablename identity_insert on" query before doing the import, which normally would allow explicit insertion of identity values, but it made no difference.  Any ideas?
0
Comment
Question by:rmcafee
4 Comments
 
LVL 2

Expert Comment

by:odessa
ID: 1090596
Try to set "IncludeIdentityValues" to false
and then run "set tablename identity_insert on" query
what's happend
0
 

Author Comment

by:rmcafee
ID: 1090597
OK, I tried all 4 permutations of BulkCopy.IncludeIdentityValues = true/false and Database.Execute("set identity_insert tablename on/off").

The resulting exported data file doesn't have any identity values in it, regardless of what I do with these flags.
0
 
LVL 3

Accepted Solution

by:
gmoriak earned 200 total points
ID: 1090598
Try running

set tablename identity_insert on

on your source table before the export AND on your destination table before the import.
0
 

Expert Comment

by:bamartino
ID: 1090599
Use the option
-E with bcp (explicit identity)
when loading data, this will allow you to keep the identity column as it comes with the file.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question