Hi,
I am trying to create a foreign key constraint consisting of an int column and a datetime column (both not null).
I am getting the error "There are no primary or candidate keys in the referenced table X that match the referencing column list in the foreign key FK".
Normally this error means that the column(s) in the target table is not unique. However it is the primary key so it is definitely unique.
The table which the foreign key is referencing is partitioned across multiple file groups - whereas the table on which the foreign key is being created resides on the primary file group. Could this be the problem? Can datetimes be part of a foreign key?
Table X:
LineId (int not null) (PK)
CreatedAt (datetime not null) (PK)
Message (nvarchar(max))
userId (int not null)
Table Y:
LineId (int not null) (PK) (FK)
SId (int not null) (PK)
LineCreatedAt (datetime not null) (FK)
CreatedAt (datetime not null)
SQL command:
ALTER TABLE Y
ADD CONSTRAINT [FK1]
FOREIGN KEY(LineId,LineCreatedAt)
REFERENCES X(LineId, CreatedAt)
Any ideas appreciated.
Thanks