Solved

Export data Identity Column Problem

Posted on 2007-11-17
8
603 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
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:tedbilly
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
 
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
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 

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 500 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 is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Join & Write a Comment

Suggested Solutions

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 article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now