-1

I'm trying to create a small application which will allow a person to handle incoming donations and distribute them among a list of receivers according to their percentage amounts which has been predetermined.

During the table design process, I have come to a place where I am unsure of how to proceed and am looking for advice in how I should design the tables. I have begun by placing all people in the same table regardless of whether they are donors or receivers because each person could potentially either give and/or receive.

As you can see below, tblGiverReceiver is the central table, however I'm not sure whether the fact that there is a circular reference will cause me problems and whether or not it is bad design from a normalization standpoint.

Here is what my design looks like:

ERD

I know the naming conventions are not correct. I am still in the design stage and find it easier to use names like this to help me think.

Should I duplicate the tblGiverReceiver table and rename each as tblGiver / tblReceiver or is it OK for me to link the table back to itself in this manner?

EDIT: I read through a suggested link from a fellow stackoverflow-er (How can you represent inheritance in a database?), however the question posed is not what I was looking for.

viRg
  • 95
  • 1
  • 11
  • 1
    Please [use text, not images/links, for text--including tables & ERDs.](https://meta.stackoverflow.com/q/285551/3404097) Paraphrase or quote from other text. Use images only for what cannot be expressed as text or to augment text. Images cannot be searched for or cut & pasted. Include a legend/key & explanation with an image. Make your post self-contained. PS Those lines between boxes aren't symmetrical in the way we would expect for 2 subtypes of a supertype. – philipxy May 07 '19 at 22:49
  • 1
    Possible duplicate of [How can you represent inheritance in a database?](https://stackoverflow.com/questions/3579079/how-can-you-represent-inheritance-in-a-database) – philipxy May 07 '19 at 22:53
  • 1
    (Obviously) This is a faq. Before considering posting please always google your error message or many clear, concise & precise phrasings of your question/problem/goal, with & without your particular strings/names, & read many answers. If you post a question, use one phrasing as title. See [ask] & the voting arrow mouseover texts. – philipxy May 07 '19 at 22:55
  • Thanks @philipxy for your timely and constructive comments. I am fairly new to database design and trying to improve. The next time I post a question involving ERD, I'll try to include it without an image. I've tried to read as much as possible on the subject before asking and went through the complete list of suggested questions previously asked by other StackOverflow users. I'm not sure the one you suggested above was in the list, but I have to admit that even if it was, it's way over my head. I've asked numerous questions on this site before and have yet to do it correctly. – viRg May 08 '19 at 01:40
  • 1
    SO is poor place to learn anything, get a textbook. There is especially a lot of relational model nonsense here & on the web. Read a published academic textbook on information modeling & database design. (Manuals for languages & tools to record & use designs are not textbooks on doing information modeling & database design.) Dozens of published academic information modeling & database design textbooks are online free in pdf. stanford.edu has a free online course. Nevertheless there are many SO questions on SQL/DB subtyping/inheritance/polymorphism. – philipxy May 08 '19 at 08:35
  • I have no idea what you mean by "duplicate the tblGiverReceiver table" or "rename each as" or "link the table back to itself" or "this manner". Or what you think is "a circular reference" here. Or what this has to do with normalization. Find & follow a a published academic textbook on information modeling & database design. (Manuals for languages & tools to record & use designs are not textbooks on doing information modeling & database design.) Dozens of published academic information modeling & database design textbooks are online free in pdf. stanford.edu has a free online course. – philipxy May 08 '19 at 08:45
  • @philipxy, thanks for the suggestion to read from textbooks as opposed to trying to learn from SO. I've enrolled in the free courses from Stanford as you suggested. Glad I did. – viRg May 09 '19 at 02:18

2 Answers2

1

Your application is about People, Addresses, Donations and Received payments so they seem to be the appropriate tables. Here is my suggestion implemented as a sample design in 5th normal form.

Tables and relationships start out as statements of facts such as "Person has LanguagePreference". I specified the facts and then used our NORMA tool to generate the schema design. Sorry but I could not understand the "percentage amounts" concept so it is not included.

Here is the schema:

enter image description here

Here are the facts from which the schema was generated.

enter image description here

Here are the constraints.

enter image description here

Ken Evans
  • 362
  • 1
  • 11
  • 1
    Thanks for your great wisdom! If I uploaded the fact lists as text I would loose the colours and it is the colours that convey meaning. – Ken Evans May 07 '19 at 22:59
  • Your comments are not a reason to not give text. (Moreover, you give no legend, so colours convey nothing.) – philipxy May 07 '19 at 23:05
  • Thanks @KenEvans. I'm going to try using the Normal Tool you used above. It will be a great help in my future designs I'm sure! – viRg May 08 '19 at 01:55
  • 1
    @viRg the NORMA tool is an extension to Visual Studio so you have to install the free Visual Studio Community Edition first. Our latest build is for Visual Studio 2019. Just follow the instructions in "Events & News" on my home page.http://www.ormfoundation.org/ – Ken Evans May 08 '19 at 08:52
  • 1
    @philipxy Blue - from first order logic Green - predicates Purple - object types. Happy now? – Ken Evans May 08 '19 at 08:57
  • Your comments are not a reason to not give text. PS Please clarify via edits, not comments. PS Please don't shoot the messenger. – philipxy May 08 '19 at 09:01
1

I thought that you might find it helpful to see the SQL DDL for the schema diagram in my earlier answer.

This DDL was also generated from our NORMA tool. It took me about 30 seconds to choose the appropriate options and then Voila! a millisecond or so later we have the SQL DDL in fifth normal form.

CREATE SCHEMA "Donations"
GO

CREATE TABLE "Donations".Person
(
    personNr int NOT NULL,
    addressNr int NOT NULL,
    firstName nchar(30) NOT NULL,
    languagePref nchar(15) NOT NULL,
    lastName nchar(40) NOT NULL,
    nickName nchar(100) NOT NULL,
    title nchar(50) NOT NULL,
    CONSTRAINT Person_PK PRIMARY KEY(personNr)
)
GO


CREATE TABLE "Donations".Address
(
    addressNr int NOT NULL,
    address1 nchar(40) NOT NULL,
    address2 nchar(40) NOT NULL,
    country nchar(40) NOT NULL,
    postalCode nchar(10) NOT NULL,
    province nchar(30) NOT NULL,
    address3 nchar(40),
    CONSTRAINT Address_PK PRIMARY KEY(addressNr)
)
GO


CREATE TABLE "Donations".Donation
(
    donationNr int NOT NULL,
    amount decimal(6,2) NOT NULL,
    "date" datetime NOT NULL,
    personNr int,
    CONSTRAINT Donation_PK PRIMARY KEY(donationNr)
)
GO


CREATE TABLE "Donations".Payment
(
    paymentNr int NOT NULL,
    amount decimal(6,2) NOT NULL,
    "date" datetime NOT NULL,
    personNr int,
    CONSTRAINT Payment_PK PRIMARY KEY(paymentNr)
)
GO


ALTER TABLE "Donations".Person ADD CONSTRAINT Person_FK FOREIGN KEY (addressNr) REFERENCES "Donations".Address (addressNr) ON DELETE NO ACTION ON UPDATE NO ACTION
GO


ALTER TABLE "Donations".Donation ADD CONSTRAINT Donation_FK FOREIGN KEY (personNr) REFERENCES "Donations".Person (personNr) ON DELETE NO ACTION ON UPDATE NO ACTION
GO


ALTER TABLE "Donations".Payment ADD CONSTRAINT Payment_FK FOREIGN KEY (personNr) REFERENCES "Donations".Person (personNr) ON DELETE NO ACTION ON UPDATE NO ACTION


GO
Ken Evans
  • 362
  • 1
  • 11