Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Export data Identity Column Problem

Posted on 2007-11-17
8
Medium Priority
?
611 Views
Last Modified: 2010-05-18
Hi,

I want to export data from my remote server to my local machine.  I want an exact copy.  The problem is that I can export data from remote dbQIIHL to local dbQIIHL but since I have identity colums the export doesn't override the identity column constraint on my local machine, hence my sql queries do not work on the local machine after the export process.

Is there a way to turn off the identity on a database, do the export, and then turn it on again so that the db behaves normally?
0
Comment
Question by:vstack
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 18

Expert Comment

by:Yveau
ID: 20305134
... export ... So I assume you are doing something with insert statements to fill the local copy of your database ?

In that case, use this function (from BOL):
SET IDENTITY_INSERT [database_name.[schema_name].] table {ON|OFF}

Turn the setting on, do the import, and turn it off again. It is off by default ... as you experienced :-)

for more info, look here:
http://msdn2.microsoft.com/en-us/library/ms188059.aspx

Hope this helps ...
0
 
LVL 51

Expert Comment

by:Ted Bouskill
ID: 20305569
I use SQL Delta from the www.sqldelta.com which has a database difference and copying tool.  It automates the process.
0
 

Author Comment

by:vstack
ID: 20306285
I am using the export wizard in SQL Server 2005
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
LVL 18

Expert Comment

by:Yveau
ID: 20306988
... the export wizard creates an SSIS package for you.
Either add two SQL Tasks in the SSIS package, or manually run the SET IDENTITY statement prior to the SSIS package and afterwards.

Hope this helps ...
0
 

Author Comment

by:vstack
ID: 20307139
Yveau, with your help, I am close to the solution.  I managed tio export all data but I had to manually click the allow Identity insert for EVERY table.  Even this did not work until I deselected the Optimize for many tables.

Is their a way to do this so that I don't have to check the 'Allow Identity Insert' for every table?
0
 
LVL 18

Accepted Solution

by:
Yveau earned 2000 total points
ID: 20309126
Sure, you can loop through every table with the cursor included in the code snippet ...

Hope this helps ...

declare @cTbl varchar(50)
declare @cSQL varchar(max)
 
declare Yveau cursor
for
select  name
from    dbo.sysobjects
where   type = 'U'
-- make sure to add enough clauses here to ONLY list the tables with IDENTITY columns !!!
 
open    Yveau
fetch   Yveau
into    @cTbl
 
while   (@@Error = 0)
and     (@@Fetch_Status = 0)
begin
        set     @cSQL = 'SET IDENTITY_INSERT '+@cTbl+' ON'
        exec    (@cSQL)
 
        fetch   Yveau
        into    @cTbl
end
 
close   Yveau
deallocate Yveau

Open in new window

0
 

Author Closing Comment

by:vstack
ID: 31409738
This works with some extra variation for my problem
0
 

Expert Comment

by:ejohnson4211
ID: 21550735
This is clearly a bug, yet I don't see it on Microsoft's KnowledgeBase as yet.  Does someone from Microsoft monitor this forum?  How do we escalate this issue to them?

Thanks!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

by Mark Wills PIVOT is a great facility and solves many an EAV (Entity - Attribute - Value) type transformation where we need the information held as data within a column to become columns in their own right. Now, in some cases that is relatively…
Introduction This article will provide a solution for an error that might occur installing a new SQL 2005 64-bit cluster. This article will assume that you are fully prepared to complete the installation and describes the error as it occurred durin…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

610 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