Quantcast
Viewing latest article 1
Browse Latest Browse All 6

Answer by K0D4 for SQL: Remove rows whose associations are broken (orphaned data)

I've found in SQL 2008 R2, if your "in" clause contains a null value (perhaps from a table who has a reference to this key that is nullable), no records will be returned! To correct, just add a clause to your selects in the union part:

delete from SomeTable where Key not in (  select SomeTableKey from TableB where SomeTableKey is not null  union  select SomeTableKey from TableC where SomeTableKey is not null)

Viewing latest article 1
Browse Latest Browse All 6

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>