Foreign Key error

  • Hi,

    I really would appreciate some advice on why I am getting the error unable to create relationship FK etc, (see below) I have created FKs on countless tables, so don't know why this is playing up.

    I have 2 tables -

    Employee - with a field AddIdOffice (int null default (null))

    AddressTest - with PK field AddressId (int not null)

    I want to create a FK between Employee.AddIdOffice and Address.AddressId in SQL2005.

    I have checked that all the AddressIds in my Employee table do actually exist in the table AddressTest.

    I just don't know what the problem could be.

    Please could someone point me in the right direction. I would be most grateful.

    Kind regards,

    Polly

    Error -

    Unable to create relationship 'FK_Employee_AddressTest'.

    The ALTER TABLE statement conflicted with the FOREIGN KEY constraint "FK_Employee_AddressTest". The conflict occurred in database "FleetVision", table "dbo.AddressTest", column 'AddressId'.

  • You already have data in the employee table that breaks the FK constraint. i.e. there is an Employee.AddIdOffice that doesn't exist in Address.AddressId

  • Hi Ian,

    yes, yes, yes. It was as simple as that.

    Thank you so much and thank you for your patience.

    Kind regards,

    Polly

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

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