I have two tables, Table_1 with 4 columns (3 primary key) and Table_2 with 2 column. When I try to create a foreign key constraint in Table_2, I am getting this error:

Here are the definitions of my tables:
Table_1
CREATE TABLE [dbo].[Table_1]
(
[Field_1] [tinyint] NOT NULL,
[Field_2] [tinyint] NOT NULL,
[Field_3] [tinyint] NOT NULL,
[Field_4] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
CONSTRAINT [PK_Table_1] PRIMARY KEY CLUSTERED
(
[Field_1] ASC,
[Field_2] ASC,
[Field_3] ASC
)
Table_2
CREATE TABLE [dbo].[Table_2]
(
[Field_1] [tinyint] NOT NULL,
[Field_2] [tinyint] NOT NULL
) ON [PRIMARY]
Do you have any idea on how to solve this? Thanks –
The primary key of
Table_1is all three ofField_1,Field_2andField_3. In order to reference a key in another table, you have to reference all of the columns in that key – so you would need to addField_2andField_3toTable_2, and have all three columns included when you attempt to create the foreign key constraint.Alternatively, if
Field_1, by itself, is a key forTable_1, then declare it as such, either by redefining the primary key, or adding aUNIQUEconstraint on justField_1toTable_1. You would then be able to create the foreign key you’re attempting to.