1 回答

TA貢獻1794條經驗 獲得超8個贊
如果小提琴不知何故不再工作,下面是 SQL 代碼。(假設MySQL/MariaDB)
create table product
(
? ? id int auto_increment,
? ? name varchar(255) not null,
? ? constraint product_pk
? ? ? ? primary key (id)
);
create table shop
(
? ? id int auto_increment,
? ? name varchar(255) not null,
? ? constraint shop_pk
? ? ? ? primary key (id)
);
create table product_shop
(
? id int auto_increment,
? product_id int,
? shop_id int,
? quantity int not null default 0,
? constraint product_shop_pk
? ? ? primary key (id)
);
alter table product_shop
? ? add constraint product_shop_product_fk
? ? ? ? foreign key (product_id) references product (id);
alter table product_shop
? ? add constraint product_shop_shop_fk
? ? ? ? foreign key (shop_id) references shop (id);
- 1 回答
- 0 關注
- 129 瀏覽
添加回答
舉報