N
N
noneim2019-12-28 17:35:09
MySQL
noneim, 2019-12-28 17:35:09

Is it possible to create a foreign key on different tables?

Let's say there is a table all_products that has a unique composite index on the src and src_id fields.

create table all_products(
id int AUTO_INCREMENT,
src int,
src_id int,
PRIMARY KEY(id),
UNIQUE KEY `src_connect` (`src`, `src_id`))

src is the source (product type)
src_id is the index of the entity in another table (the table is determined depending on the src)
Is it possible to make src_id as a foreign key? (Someone too smart now swears that there are no links between tables ... but the all_products table is needed, because in addition to local tables, there are also products loaded via api)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lazy @BojackHorseman MySQL, 2019-12-28
Tag

no.
such constraints can only be implemented by triggers

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question