Foreign Key constraints problem

  • Greetings,

    I am trying to set up a table which has 2 fields that have a foreign key constraint to the same primary key in another table. When I run the script, I get this error:

    Server: Msg 8139, Level 16, State 1, Line 3

    Number of referencing columns in foreign key differs from number of referenced columns,

    I've also tried setting up both of these columns under one FK constraint, but I get the same error. Is there any way to do this?

  • Is this what you are looking for:

    create table t2 (id int identity primary key)

    create table t3 (id int identity,

    a int references t2(id),

    b int references t2(id))

    -------------------------

    Gregory Larsen, DBA

    If you looking for SQL Server Examples check out my website at http://www.geocities.com/sqlserverexamples

    Gregory A. Larsen, MVP

  • Actually, I forgot one detail....I am trying to set up cascading updates on these FK's as well....your script works, but if you try to set up cascading updates with it, it will give you the multiple paths error...is there any way to set this up?

  • Details......

    Check out this article for more information about your problem.....

    http://support.microsoft.com/default.aspx?scid=kb;en-us;q321843

    -------------------------

    Gregory Larsen, DBA

    If you looking for SQL Server Examples check out my website at http://www.geocities.com/sqlserverexamples

    Gregory A. Larsen, MVP

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

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