Skip to content
Advertisement

Can Foreign Key on a table be three different tables as primary keys (each table primary key data is different)?

I have a reminder table (ParentId) – Foreign key to ProductId from Product and also OrderId from Order table. Is it possible? When I try to insert the data for the Reminder table belongs to OrderId, I’m getting Foreign-Key constraint error.

Advertisement

Answer

You can do this with a bit of work, using foreign key relationships and computed columns. This does require a “type” of some sort in the table:

Here is a db<>fiddle.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement