SQL Server 2005.
I am adding foreign key constraints to the application database, which supposedly did not need them. Naturally, the data became unreliable, and there are orphaned entries in the foreign key field.
Setup:
Two tables, TableUser and TableOrder. TableUser has the primary key 'UserID', and TableOrder has the foreign key 'UserID'.
How to find rows where TableOrder.UserID does not have a corresponding entry in TableUser.UserID?
For example, TableOrder.UserID is set to 250, but there is no corresponding Key for TableUser.UserID for 250.
source
share