Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to keep DTS copy from re-autonumbering?

Posted on 2006-11-16
6
Medium Priority
?
321 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 750 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 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

SET IDENTITY_INSERT TableName ON
Insert MyTable (Col1,Col2,Col3)
Select  Col1,Col2,Col3 from Remote_Table
SET IDENTITY_INSERT TableName OFF
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

926 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