How to keep DTS copy from re-autonumbering?

Posted on 2006-11-16
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?

Question by:marms767
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
  • 3
  • 2
LVL 29

Assisted Solution

Nightman earned 250 total points
ID: 17959848
do you inserts

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

Author Comment

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.
LVL 11

Accepted Solution

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

Insert MyTable (Col1,Col2,Col3)
Select  Col1,Col2,Col3 from Remote_Table
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!


Author Comment

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?
LVL 11

Expert Comment

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...
LVL 11

Expert Comment

ID: 17966771
let me check one more possibilty in DTS, will get back to you

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

739 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