Solved

How to keep DTS copy from re-autonumbering?

Posted on 2006-11-16
6
265 Views
Last Modified: 2006-11-20
I have a DTS that runs every night that copies tables from one SQL Server to another for using in a "backup-system" of an application.

I am doing a Transform Data Task from the one table to an exact copy of the table on the other server for several tables. The problem I have is that the primary key on all the tables on the back-up system are all re-numbered and causes all the normalization to be incorrect between tables.

Can I remove the "Identity Increment" off all these tables before the copy and then put it on after the copy? What T-SQL statements would I run to do both removal and adding them back on in the DTS?

Thanks
0
Comment
Question by:marms767
  • 3
  • 2
6 Comments
 
LVL 29

Assisted Solution

by:Nightman
Nightman earned 250 total points
ID: 17959848
SET IDENTITY_INSERT TableName ON
do you inserts
SET IDENTITY_INSERT TableName OFF

Not that this is specific to the SQL batch that you are executing, so all inserts have to occur between those 2 statements.
0
 

Author Comment

by:marms767
ID: 17960062
How would those statements work in my case within the DTS ?
I am not doing a "INSERT INTO () SELECT * FROM" between two database on the same SQL Server, but am doing a Transform Data Task where the "Source" tab has a Connection to a remote SQL server and "Table / View" is selected and the dropdown has the table selected. Then on the "Destination" tab it has a connection to the Local SQL server with the table selected.

It is the destination that I would need to "SET IDENTITY_INSERT TableName ON" and then "SET IDENTITY_INSERT TableName OFF" again, but there is no SQL option in the "Destination" tab.

Please advise.
0
 
LVL 11

Accepted Solution

by:
rw3admin earned 250 total points
ID: 17961108
Create another table on Destination with same structure as the Destination table but without PK and Identity constraint.

now pull all your data from Source to this table, and then write another "Execute SQL Task" step, do what Nightman told you, just one thing to remember, while inserting with SET IDENTITY_INSERT TableName ON you have to explictly porvide column list in both Insert and select parts for example

SET IDENTITY_INSERT TableName ON
Insert MyTable (Col1,Col2,Col3)
Select  Col1,Col2,Col3 from Remote_Table
SET IDENTITY_INSERT TableName OFF
0
Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

 

Author Comment

by:marms767
ID: 17966469
Is there any other way to go about this? I would have 31 tables to duplicate on the local server and one of them contains 900 thousand records.

Is it not possible to remove Identity Increment off the table then put it back on as I originally suggested?
0
 
LVL 11

Expert Comment

by:rw3admin
ID: 17966764
>>Is it not possible to remove Identity Increment off the table then put it back on as I originally suggested?<<

yes SET IDENTITY_INSERT TableName ON is exactly doing that, its turning off Identity increment in your table, but you cant do that in that DTS step where you just have destination and source tables and the transformation link on each column.... now if your original issue can be avoided
>>The problem I have is that the primary key on all the tables on the back-up system are all re-numbered and causes all the normalization to be incorrect between tables.<<

then go to that transformation step and drop the transformations betwen this identity column.

you might think if we insert couple of "execute sql task" steps one before and one after your data transformation task. and you put SET IDENTITY_INSERT TableName ON in before and SET IDENTITY_INSERT TableName OFF in after things might work, I think it will fail but hey no points for not trying...

another option is to alter table and re-alter it remove identity and add it back again, thats more trouble then trying to create another physical table cause you cant just add and remove Identity to a column, you will have to create another column move date from this col to new col, re-create identity col without identity and insert data using DTS then repeating these steps to create identity on this column

I wish I could help more...
0
 
LVL 11

Expert Comment

by:rw3admin
ID: 17966771
let me check one more possibilty in DTS, will get back to you
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

In this article—a derivative of my DaytaBase.org blog post (http://daytabase.org/2011/06/18/what-week-is-it/)—I will explore a few different perspectives on which week today's date falls within using Microsoft SQL Server. First, to frame this stu…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

747 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

10 Experts available now in Live!

Get 1:1 Help Now