i have 2 cases in which i am facing some issues.How to delete records when from one table A and Table B
for scenario : Case 1 : table A have 100 records and Table B have 200 records
now i need to insert data of table A into table B so in need to delete as well as insert how it can be possible??? Case 2 : in another case i need to insert and update
insert into Speciality(SpecialityName,Description,SpecialityCode,CreatedByUserId) select SpecialityName,Description,SpecialityCode,21 from Speciality1 where exists (select 1 from Speciality)
MERGE TableB as b USING TableA as a ON yourCondition WHEN MATCHED THEN UPDATE SET b.col1 = a.col1, b.col2 = a.col2 ............ WHEN NOT MATCHED THEN DELETE;
MERGE TableB as b USING TableA as a ON yourCondition WHEN MATCHED THEN UPDATE SET b.col1 = a.col1, b.col2 = a.col2 ............ WHEN NOT MATCHED BY SOURCE THEN DELETE;