Home Forums SQL Server 2008 SQL Server 2008 - General Getting stumped when trying to delete records from a table. Need help, please. RE: Getting stumped when trying to delete records from a table. Need help, please.

  • The foreign key is on the column InventoryInDetailID.

    ALTER TABLE [dbo].[PharmInvOutItemPackageReceipts] WITH CHECK ADD CONSTRAINT [FK_PharmInvOutItemPackageReceipts_PharmInvInItemPackages] FOREIGN KEY([InventoryInDetailID])

    REFERENCES [dbo].[PharmInvInItemPackages] ([InventoryInDetailID])

    You are joining in the delete on the column InvOutItemLineID.

    DELETE pp

    FROM PharmInvOutItemPackages pp

    INNER JOIN PharmInvOutItemPackageReceipts pr

    ON pp.[InvOutItemLineID] = pr.[InvOutItemLineID]

    WHERE pr.DateEntered < @CutOffDate

    So there's no reason to expect that the correct child rows have been deleted because that's not the foreign key column.