Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


merge script issuse in sql server .


merge script issuse in sql server .

Author
Message
asranantha
asranantha
SSC Veteran
SSC Veteran (216 reputation)SSC Veteran (216 reputation)SSC Veteran (216 reputation)SSC Veteran (216 reputation)SSC Veteran (216 reputation)SSC Veteran (216 reputation)SSC Veteran (216 reputation)SSC Veteran (216 reputation)

Group: General Forum Members
Points: 216 Visits: 4717
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 .
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