-- サンプル テーブル作成 -- 顧客 create table customers ( id int AUTO_INCREMENT not null comment '顧客ID' , name VARCHAR(255) not null comment '名前' , constraint customers_PKC primary key (id) ) comment '顧客' ENGINE = 'InnoDB'; -- 利用プラン一覧 create table service_plans ( id int AUTO_INCREMENT not null comment 'ID' , customer_id INT not null comment '顧客ID' , category VARCHAR(50) not null comment 'カテゴリー' , plan VARCHAR(50) not null comment '利用プラン' , constraint service_plans_PKC primary key (id) ) comment '利用プラン一覧' ENGINE = 'InnoDB'; -- customer_id, category に ユニークインデックスを設定 alter table service_plans add unique idx_customer_category (customer_id,category) ; -- サンプル データ作成 INSERT INTO customers (id, name) VALUES (101, 'アルパカ太郎'); INSERT INTO service_plans (id, customer_id, category, plan) VALUES (1, 101, '髭脱毛コース', 'Aプラン'); INSERT INTO service_plans (id, customer_id, category, plan) VALUES (2, 101, '背中脱毛コース', 'Bプラン');