Solved

Export data Identity Column Problem

Posted on 2007-11-17
8
604 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: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
 
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
Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

 

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

There are some very powerful Data Management Views (DMV's) introduced with SQL 2005. The two in particular that we are going to discuss are sys.dm_db_index_usage_stats and sys.dm_db_index_operational_stats.   Recently, I was involved in a discu…
by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

910 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

23 Experts available now in Live!

Get 1:1 Help Now