SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Data update from one database to another database (Insert and Update both)


Data update from one database to another database (Insert and Update both)

Author
Message
sumit.joshij
sumit.joshij
SSC Veteran
SSC Veteran (202 reputation)SSC Veteran (202 reputation)SSC Veteran (202 reputation)SSC Veteran (202 reputation)SSC Veteran (202 reputation)SSC Veteran (202 reputation)SSC Veteran (202 reputation)SSC Veteran (202 reputation)

Group: General Forum Members
Points: 202 Visits: 269
Hi,
I have 2 database tables.
1) From Production
2) From Dev.
The task is to move the data from Production to Dev Server.
But the issues is that when the data is already exist then it will update else if no record exist in Dev Server then it will insert.

Existence of Data is checked through one column.

please respond asap if you have any good solution.
Daniel Bowlin
Daniel Bowlin
SSCrazy Eights
SSCrazy Eights (8K reputation)SSCrazy Eights (8K reputation)SSCrazy Eights (8K reputation)SSCrazy Eights (8K reputation)SSCrazy Eights (8K reputation)SSCrazy Eights (8K reputation)SSCrazy Eights (8K reputation)SSCrazy Eights (8K reputation)

Group: General Forum Members
Points: 8034 Visits: 2629
This is pretty straight forward in SSIS

In a dataflow,
-create a source from your prod server.
-Lookup records on your dev server. In SQL Server 2005 I believe you have to set it to ignore the failure
-Create a conditional split that compares the value in your source (prod) to the value you target (dev)
-In the split where they match send the data to a staging table
-In the split where they don't match send the data to be inserted to your target.

After the data flow runs, build an Execute SQL Task that takes the matched data from your staging table and updated the target (dev) data.
sumit.joshij
sumit.joshij
SSC Veteran
SSC Veteran (202 reputation)SSC Veteran (202 reputation)SSC Veteran (202 reputation)SSC Veteran (202 reputation)SSC Veteran (202 reputation)SSC Veteran (202 reputation)SSC Veteran (202 reputation)SSC Veteran (202 reputation)

Group: General Forum Members
Points: 202 Visits: 269
thanks. its working in some of my test sample data.
Daniel Bowlin
Daniel Bowlin
SSCrazy Eights
SSCrazy Eights (8K reputation)SSCrazy Eights (8K reputation)SSCrazy Eights (8K reputation)SSCrazy Eights (8K reputation)SSCrazy Eights (8K reputation)SSCrazy Eights (8K reputation)SSCrazy Eights (8K reputation)SSCrazy Eights (8K reputation)

Group: General Forum Members
Points: 8034 Visits: 2629
Daniel Bowlin (12/24/2012)
This is pretty straight forward in SSIS

In a dataflow,
-create a source from your prod server.
-Lookup records on your dev server. In SQL Server 2005 I believe you have to set it to ignore the failure
-Create a conditional split that compares the value in your source (prod) to the value you target (dev)
-In the split where they match send the data to a staging table
-In the split where they don't match send the data to be inserted to your target.

After the data flow runs, build an Execute SQL Task that takes the matched data from your staging table and updated the target (dev) data.


A couple of revisions
In the no match, that actually would get sent to an update process, not insert
There should be a null in some of your lookup values, the nulls would be the new records that should be inserted.
sumit.joshij
sumit.joshij
SSC Veteran
SSC Veteran (202 reputation)SSC Veteran (202 reputation)SSC Veteran (202 reputation)SSC Veteran (202 reputation)SSC Veteran (202 reputation)SSC Veteran (202 reputation)SSC Veteran (202 reputation)SSC Veteran (202 reputation)

Group: General Forum Members
Points: 202 Visits: 269
Thanks a lot.
nick.mcdermaid
nick.mcdermaid
SSC Eights!
SSC Eights! (854 reputation)SSC Eights! (854 reputation)SSC Eights! (854 reputation)SSC Eights! (854 reputation)SSC Eights! (854 reputation)SSC Eights! (854 reputation)SSC Eights! (854 reputation)SSC Eights! (854 reputation)

Group: General Forum Members
Points: 854 Visits: 782
Since you just want to duplicate the table, you might find it quicker and simpler to just bulk reload the entire table, depending on data volume.
HildaJ
HildaJ
Ten Centuries
Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)

Group: General Forum Members
Points: 1071 Visits: 571
Have you considered replication? That might be an option.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search