我正在尝试找出归一化问题,以将其解决为3NF。
以下是我遇到的问题。
FeedTheChildrenMinistries (donorID, donorName, childID, childName, countryCode, countryName, countryPopulation, regularMonthlyDonationAmy, extraDonationTotal)
这些是问题的业务规则。
我知道施主名称和后代名称应按以下表格分类。
donorName (donor_first, donor_last)
childName (child_first, child_last)
我只是不确定PK,PD和TD。
答案 0 :(得分:0)
这是您的第5个范式的逻辑模型。
这是T-SQL DDL,可用于在SQL Server中生成数据库。
/*
T-SQL DDL for the FeedTheChildrenMinistries.
Copyright (C) 2019 Ken Evans, The ORM Foundation.
This is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License Version 3 as published by
the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
CREATE SCHEMA FeedTheChildrenMinistries
GO
CREATE TABLE FeedTheChildrenMinistries.Donor
(
donorId int NOT NULL,
firstName nchar(40) NOT NULL,
lastName nchar(40) NOT NULL,
CONSTRAINT Donor_PK PRIMARY KEY(donorId)
)
GO
CREATE TABLE FeedTheChildrenMinistries.Child
(
childId int NOT NULL,
countryCode nchar(10) NOT NULL,
firstName nchar(40) NOT NULL,
lastName nchar(40) NOT NULL,
donorId int,
CONSTRAINT Child_PK PRIMARY KEY(childId)
)
GO
CREATE TABLE FeedTheChildrenMinistries.Country
(
countryCode nchar(10) NOT NULL,
countryName nchar(100) NOT NULL,
countryPopulation int NOT NULL,
CONSTRAINT Country_PK PRIMARY KEY(countryCode)
)
GO
CREATE TABLE FeedTheChildrenMinistries.DonorMakesExtraDonationForChild
(
donorId int NOT NULL,
extraDonation decimal(6,2) NOT NULL,
childId int NOT NULL,
CONSTRAINT DonorMakesExtraDonationForChild_PK PRIMARY KEY(donorId, extraDonation)
)
GO
CREATE TABLE FeedTheChildrenMinistries.DonorMakesMonthlyDonationForChild
(
donorId int NOT NULL,
monthlyDonation decimal(6,2) NOT NULL,
childId int NOT NULL,
CONSTRAINT DonorMakesMonthlyDonationForChild_PK PRIMARY KEY(donorId, monthlyDonation)
)
GO
ALTER TABLE FeedTheChildrenMinistries.Child ADD CONSTRAINT Child_FK1 FOREIGN KEY (donorId) REFERENCES FeedTheChildrenMinistries.Donor (donorId) ON DELETE NO ACTION ON UPDATE NO ACTION
GO
ALTER TABLE FeedTheChildrenMinistries.Child ADD CONSTRAINT Child_FK2 FOREIGN KEY (countryCode) REFERENCES FeedTheChildrenMinistries.Country (countryCode) ON DELETE NO ACTION ON UPDATE NO ACTION
GO
ALTER TABLE FeedTheChildrenMinistries.DonorMakesExtraDonationForChild ADD CONSTRAINT DonorMakesExtraDonationForChild_FK1 FOREIGN KEY (donorId) REFERENCES FeedTheChildrenMinistries.Donor (donorId) ON DELETE NO ACTION ON UPDATE NO ACTION
GO
ALTER TABLE FeedTheChildrenMinistries.DonorMakesExtraDonationForChild ADD CONSTRAINT DonorMakesExtraDonationForChild_FK2 FOREIGN KEY (childId) REFERENCES FeedTheChildrenMinistries.Child (childId) ON DELETE NO ACTION ON UPDATE NO ACTION
GO
ALTER TABLE FeedTheChildrenMinistries.DonorMakesMonthlyDonationForChild ADD CONSTRAINT DonorMakesMonthlyDonationForChild_FK1 FOREIGN KEY (donorId) REFERENCES FeedTheChildrenMinistries.Donor (donorId) ON DELETE NO ACTION ON UPDATE NO ACTION
GO
ALTER TABLE FeedTheChildrenMinistries.DonorMakesMonthlyDonationForChild ADD CONSTRAINT DonorMakesMonthlyDonationForChild_FK2 FOREIGN KEY (childId) REFERENCES FeedTheChildrenMinistries.Child (childId) ON DELETE NO ACTION ON UPDATE NO ACTION
GO