Это логическая модель вашей проблемы в 5-й нормальной форме.
Это DDL T-SQL, который можно использовать для создания базы данных в 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