归一化问题的部分依赖性,

时间:2019-04-12 21:27:05

标签: database

我正在尝试找出归一化问题,以将其解决为3NF。

以下是我遇到的问题。

FeedTheChildrenMinistries (donorID, donorName, childID, childName, countryCode, countryName, countryPopulation, regularMonthlyDonationAmy,  extraDonationTotal)

这些是问题的业务规则。

  • 捐助者可以以不同的捐助额来资助许多孩子。
  • 一个孩子只能由一个捐赠者资助
  • countryCode和countryName是孩子的
  • 为特定孩子的额外捐款
  • 额外捐款总额是该年特定儿童所有额外捐款的总数
  • 每个国家/地区都有特定的名称和人口。

我知道施主名称和后代名称应按以下表格分类。

donorName (donor_first, donor_last)
childName (child_first, child_last)

我只是不确定PK,PD和TD。

1 个答案:

答案 0 :(得分:0)

这是您的第5个范式的逻辑模型。

enter image description here


这是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