• 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