Problem creating FKey

  • I am creating a new table with a foreign key into another table that already has records (over 960,000).

    When trying to create the FK, of course the new table is empty, I get this error:

    There are no primary or candidate keys in the referenced table 'dbo.ptPayments' that match the referencing column list in the foreign key 'FK_ptPaymentBatches_ptPayments'.

    ALTER TABLE [dbo].[ptPaymentBatches] WITH CHECK ADD CONSTRAINT [FK_ptPaymentBatches_ptPayments] FOREIGN KEY([PaymentBatchID])

    REFERENCES [dbo].[ptPayments] ([PaymentBatchID])

    Is there a way around this?

  • Is [dbo].[ptPayments] ([PaymentBatchID]) a primary key or does it have a unique constraint/index?

  • Neither. However, I fixed it by removing all records in ptPayments per instructions from up above.

    The table will be populated by a conversion routine from another DB.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply