M
mscertified
I have a table of around 50,000 rows (table A) and another table of around
5000 rows (table B).
There is a foreign key in table A pointing to table B.
Periodically, table A records are archived leaving 'orphan' keys in table B.
I need a query that deletes the orphan rows in table B.
I tried DELETE * FROM TableB WHERE ID NOT IN (SELECT ClientID FROM TableA)
however, it takes forever to run.
5000 rows (table B).
There is a foreign key in table A pointing to table B.
Periodically, table A records are archived leaving 'orphan' keys in table B.
I need a query that deletes the orphan rows in table B.
I tried DELETE * FROM TableB WHERE ID NOT IN (SELECT ClientID FROM TableA)
however, it takes forever to run.