Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


How to keep DTS copy from re-autonumbering?

Posted on 2006-11-16
Medium Priority
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 750 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 750 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
Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.


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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database 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.

722 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