I was trying to understand the concept of orphaned rows in a database and how they can be found and removed.
Say for example you had 2 tables (person,dog) and there was a 1-to-1 relationship between them so every person must have a dog and every dog must have an owner.
Person table:
ID Name
1 James
2 Matt
3 Mike
Dog table:
ID Name Owner_id
1 Sam 1
2 Rex 2
3 Max 3
4 Fred 4
Now if i joined those tables with:
SELECT *
FROM Person P
FULL OUTER JOIN Dog D ON P.id = D.Owner_id
This would produce a result where dog (fred) doesnt have an owner and just appears as NULL.
Is this therefore an orphaned row as it should have a matching owner?
Is this only caused due to no primary/foreign keys?
How can orphaned rows been found in a database?