Solved

How to keep DTS copy from re-autonumbering?

Posted on 2006-11-16
6
286 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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
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.
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
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

821 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