I just noticed few tables that has orphan records (foreign keys) that no longer point to any primary key. How can I query the tables to get a list of all such rows? When these parent records got deleted or how to handle this?
I'm using SQL Server 2008 R2 and we are trying to import 3 similar databases into one after cleaning it up, please advise.
Scripted a sample child table (DocumentDistribution) and parent table (DocumentSource):
ALTER TABLE [dbo].[DocumentDistribution] WITH NOCHECK ADD CONSTRAINT [fk_documentdistsourceid_documentsourceid] FOREIGN KEY([DocumentDistSourceID]) REFERENCES [dbo].[DocumentSource] ([DocumentSourceID])
GO
ALTER TABLE [dbo].[DocumentDistribution] CHECK CONSTRAINT [fk_documentdistsourceid_documentsourceid]
Doesnt that tell me that the tables are in relationships and explicitely defined the foreign key constraints?