Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

merge script issuse in sql server . Expand / Collapse
Author
Message
Posted Sunday, August 18, 2013 3:32 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Today @ 3:48 AM
Points: 209, Visits: 4,502
hi friends i have small doubt in sql server plese tell me how to solve this issuse in sql server
i have 3 tables 1 for source table and 2nd for target table and 3rd for maintain deletes records table and

table name is cdc_source and id & sal are int datatypes and (name,dname,databasename )are varchar datatypes and
data like below

id name sal dname databasename
1 veu 15 gr db1
2 eu 1 jr db2
3 jd 60 vr db2
4 pd 80 tr db2


target table is cdc_target
id name sal dname databasename


maintain delete table is cdc_deletes

id name sal dname databasename

Here i implement query useing merge script in sql server to maintain delete records in other table(cdc_deletes) as well as to maintain
and source records changed (insert/updated/deleted)that would be effected target table(cdc_target).
first time i ran query that time what ever records in source table that records goes to target table.and next time i deleted
one record in source table .and again i run query that time what ever i deleted record in source that records also deleted
in target table.here i want maintain what ever i deleted records that records maintain to deleted tables.

i tried query like below
merge cdc_target.dbo.emp t
using cdc_source.dbo.emp s
on t.id=s.id and t.databasename=s.databasename
when matched then
update set t.name=s.name,
t.sal=s.sal ,
t.dname=s.dname
when not matched by target then
insert (id,name,sal,dname,databasename)values(s.id,s.name,s.sal,s.dname,s.databasename)
when not matched by target then
insert into cdc_source.dbo.cdc_deletes
select * from cdc_target.dbo.emp where id not in(
select id from cdc_source.dbo.emp);

when not matched by target then
--when not matched by source then
delete ;

but its not given exacetly.plese tell me how to solve this issuse useing merge script in sql server .
Post #1485572
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse