gpt4 book ai didi

mysql - 表的规范化

转载 作者:搜寻专家 更新时间:2023-10-30 23:43:26 25 4
gpt4 key购买 nike

如何规范化这些表:由于我无法在复合键的部分部分上创建外键。 strong text 表示数据库中的主键。

产品(商品代码、商品名称、售价)

供应商(供应商名称、电话、地址)

SupplierProducts(SupplierName, ItemCode, SupplyPrice)

最佳答案

create table Products
( ItemCode int auto_increment primary key,
ItemName varchar(100) not null,
SellingPrice decimal(10,2) not null,
updateDt datetime not null
-- throw in some indexes
);

create table Suppliers
( SupplierId int auto_increment primary key,
SupplierName varchar(100) not null -- allows you to change a supplier name
-- throw in some indexes once you add more columns
);

create table SupplierPhone
( id int auto_increment primary key,
SupplierId int not null,
PhoneNum varchar(20) not null,
PhoneType int not null, -- have a FK somewhere
-- FK back to Suppliers
-- throw in some indexes
key (SupplierId)
);

create table SupplierAddr
( id int auto_increment primary key,
SupplierId int not null,
Addr1 varchar(100) not null,
Addr2 varchar(100) not null,
-- etc all that jazz
AddrType int not null, -- have a PK somewhere
-- FK back to Suppliers
-- throw in some indexes
key (SupplierId)
);

create table SupplierProducts
( id int auto_increment primary key,
SupplierId int not null,
ItemCode int not null,
SupplyPrice decimal(10,2) not null,
updateDt datetime not null,
-- FK back to Suppliers
-- FK back to Products
-- throw in some indexes
unique key (SupplierId,ItemCode) -- won't allow dupes on this combo
);

关于mysql - 表的规范化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32190459/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com