I am not sure I understand your question, but I am guessing a little: You have table A with PK column ID and table B with column AID and you want to know if there are rows in B where AID is not in A? Select * From B where AID not in (select ID from A)
The easiest way to do this that I know of would be to do a JOIN operation. You can use OUTER JOIN and look for NULL values. Something like: SELECT
x.ID FROM dbo.TableY AS y LEFT JOIN dbo.TableX AS x ON
x.ID You can add a WHERE clause that either filters for the parent table, Y, ID value, or just looks for IS NULL or IS NOT NULL on the child table, X, ID value.
A -- Primary Key table B -- Foreign Key table Below query returns the values in primary table and which are not in foreign key table or child table. Select * From A where ID not in (select ID from B) If you want to check for a specified value then run the below by replace the question mark(?) with the value, Select * From A where ID not in (select ID from B) and Id = ?