私は mysql の bd スキームを設計しています。私のデータベースには、a、b、または c の 3 種類のポイントが格納されており、パスは n ペアのポイントで構成されています。
ルート = [ (a1 または b1 または c1 ; a2 または b2 または c2), (a2 または b2 または c2 ; a3 または b3 または c3), ...]
create table a_points (
point_id serial not null,
owner_id bigint unsigned not null,
name varchar(20) not null,
primary key (point_id),
foreign key (owner_id) references othertable (other_id)
) engine = InnoDB;
create table b_points (
point_id serial not null,
owner_id bigint unsigned not null,
name varchar(20) not null,
fields varchar(20) not null,
primary key (point_id),
foreign key (owner_id) references othertable (owner_id)
) engine = InnoDB;
create table c_points (
point_id serial not null,
name varchar(20) not null,
cfields varchar(20) not null,
primary key (point_id)
) engine = InnoDB;
create table paths (
path_id serial not null,
name varchar(20) not null,
primary key (path_id)
) engine = InnoDB;
create table point_pairs (
pair_id serial not null,
path_id bigint unsigned not null,
point_from bigint unsigned not null,
point_to bigint unsigned not null,
table_from varchar(9) not null,
table_to varchar(9) not null,
primary key (pair_id),
foreign key (path_id) references paths (path_id)
) engine = InnoDB;
(*) ポイントのペアは (m, n) または m から n まで
そのため、パスのIDとともにポイントのペアを保存しています。私の問題は、テーブルの名前 m と n を識別する 2 つの列を作成しなければならなかったことです。m の場合は table_from、n の場合は table_to です。したがって、コードでこれら 2 つの列を使用して、ルートに保存されているポイントの種類 (path と point_pairs テーブル) を知る必要があります。私の質問: MySql は、同じ列で n 個の外部キーを参照するためのものを提供していますか? a、b、c のポイント テーブルを結合することは既に考えていましたが、この新しいテーブルに type 列を追加する必要があり、私の php クラスは役に立たなくなります。
前もって感謝します!