error sql71516

  • i work on visual stduio 2013 (C#) i work on school project .My problem when i want create relationship between tables

    ClassTab contain

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

    ClassNum Primary Key(PK)

    BranchID Primary Key (PK) and also Foregion Key (Fk)

    SysNum Primary Key (PK) and also Foregion Key (Fk)

    StageNum Foregion Key (Fk)

    ...............

    ................

    ///-----------------------------------------------//

    ***************in ClassTab*******************

    CONSTRAINT [pk-ClassTab] PRIMARY KEY CLUSTERED ([ClassNum] ASC),([BranchId] ASC),([SysNum] ASC)

    CONSTRAINT [Fk-ClassTab-Totable] FOREIGN KEY ([BranchId]) REFERENCES [Branches]([BranchId]) ,

    CONSTRAINT [Fk-ClassTab-Totable1] FOREIGN KEY ([SysNum]) REFERENCES [SysTab]([SysNum]) ,

    CONSTRAINT [Fk-ClassTab-Totable2] FOREIGN KEY ([StageNum]) REFERENCES [StageTab]([StageNum]) ******** here show error sql71516 [[The referenced table '[dbo].[ClassTab]' contains no primary or candidate keys that match the referencing column list in the foreign key.]]************

    ////////////////////////////////////////////////////////////////////////////////

    BranchesTab

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

    BranchID (PK)

    .......

    ..........

    ////////////////////////////////////////////////////////////////////////////////

    SysTab

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

    SysNum (Pk)

    .....

    ......

    ////////////////////////////////////////////////////////////////////////

    Subjtable

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

    SubjNum PK

    ClassNum Fk

    BranchID PK-FK

    SysNum PK-FK

    ........

    ........

    ////--------------------------------------------------------///

    *******************SubjTab*********************

    CONSTRAINT [pk-SubjTab] PRIMARY KEY CLUSTERED ([SubjNum] ASC),([BranchId] ASC),([SysNum] ASC)

    CONSTRAINT [Fk-SubjTab-Totable] FOREIGN KEY ([BranchId]) REFERENCES [Branches]([BranchId]) ,

    CONSTRAINT [Fk-SubjTab-Totable1] FOREIGN KEY ([SysNum]) REFERENCES [SysTab]([SysNum]) ,

    CONSTRAINT [Fk-SubjTab-Totable2] FOREIGN KEY ([ClassNum]) REFERENCES [ClassTab]([ClassNum]) ************** here show error again **************

    /////////////////////////////////////////////////////////

    StageTab

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

    StageNum Pk

    ....

    ......

    ////////////////////////////////////////////////////////////////////////

    i dont khnow what is wrong

  • I think this is a dependency issue.

    Its difficult to see, as we don't know the order the tables are created or the data types of the tables, its is possible there is an issue with the order in which you are creating the tables and constraints.

    Eg StageTab has to have a PK created before you can apply the Foreign key from SubjTable and ClassTab.

    it also has to be the same data type, which could be another possible issue.

    _________________________________________________________________________
    SSC Guide to Posting and Best Practices

  • You must have a primary key or a unique constraint in one table in order to match that table to another through a foreign key constraint. Further, the data types and number of columns between the primary key/unique constraint must be the same as the data type and number of columns in the foreign key. This error is very explicit:

    The referenced table '[dbo].[ClassTab]' contains no primary or candidate keys that match the referencing column list in the foreign key

    You're missing an important step. Either the columns don't exist, the data types are wrong, or the constraint on dbo.ClassTab doesn't exist.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

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

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