I have two tables, and I'm looking to create a foreign key constraint between them. The tables are essentially structured as follows:
Table 1:
| Name | Description | idx |
|---|
Table 2:
| Tbl1_idx1 | Tbl1_idx2 | idx |
|---|
Both tables use the idx column as their primary key, and there is a unique constraint on the combination of the other two columns in Table 2. Both of these columns are to be limited to the values available in the idx column in Table 1, hence the foreign key. However, when I attempt to run the following query:
ALTER TABLE [Table2]
ADD CONSTRAINT [FK_Table2]
FOREIGN KEY ([Tbl1_idx1], [Tbl1_idx2]) REFERENCES [Table1]([idx])
ON DELETE CASCADE
It returns that the number of referencing columns differs from the number of referenced columns. However, if I then repeat the referenced idx column into the query it returns that a duplicate columns was specified.
How can I create a foreign key that requires both columns to reference the same column? I've also tried creating two foreign keys but that returned another error, saying that this may cause multiple cascade paths. Both columns require a cascade upon deletion from Table 1.