Delete orphan Records

Could someone confirm this will delete orphan records from the child table Component where the Analysis and version don't exisit in the paretn table.

Parent key field are Name, Version
Child is Analayis, Version

component.analysis = analysis.name
DELETE ANALYSIS_VARIATION c where  NOT EXISTS (select name, version from analysis a where c.analysis = a.name and c.version=a.version)

Open in new window

gilnariAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
slightwv (䄆 Netminder)Connect With a Mentor Commented:
Look like it should.  What makes you think it might not?

I suggest you create some sample tables with sample data and test it.
0
 
gilnariAuthor Commented:
sorry I grab the wrong script

DELETE component c where  NOT EXISTS (select name, version from analysis a where c.analysis = a.name and c.version=a.version)
0
 
gilnariAuthor Commented:
The database this has to run against I don't have access to and the person that is DBA does not understand Oracle SQL (long story and scary one at that).  I pretty sure it  will work but just watned a second opinion as if it goes wrong...oh that won't be good..   I did a short test on a different development system that I have locally and it seems to do what I wanted but the reason I have orphans is the first script that ran that was suppose to take care of the child then the parent.  However when it ran  and for r some reason the child stayed behind.  Guess it was bad parenting.

Better yet there is no relationships in the data base...thats right no ref int.   again a very long story..

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.