Sql-server – Delete rows in a table based on a table value parameter

deletesql servertable-valued-parameters

I have a table A and a user defined table type on which a table value parameter (tvp) tvpA is based. Both have the same column structure except that tvpA is not defined with any constraint.

What I'd like to do is to delete rows in A that are not in tvpA based on one of their field called ID.

How can I do that ?

Best Answer

Is there a reason this simple correlated delete statement won't do the trick?

DELETE A
FROM TABLE_A A
WHERE NOT EXISTS (
        SELECT *
        FROM TVP_A
        WHERE ID = A.ID
        )