I am using Table Value Parameter to merge my records, but on top of that I will also need to delete records from my DB that do not exist in my TVP table. Can anyone please kindly assist. Thanks.
An alternative is to simply delete off all records first than proceed to insert but the quantity of the records can be up to thousands hence performance could be a concern.
MERGE [Customer_Address] ca --[AS TARGET]
USING @TvpCustomer_Address tca --[AS SOURCE]
ON (ca.CustomerId = tca.CustomerId)
AND(ca.[Address] = tca.[Address])
WHEN NOT MATCHED THEN
INSERT (CustomerId, [Address]) Values(tca.CustomerId, tca.[Address]);
WHEN MATCHED THEN
-- Update...