trying to figure out the best database schema

主宰稳场 提交于 2019-12-09 04:33:26

Here's how I'd model the database based on the provided info:

EVENTS

  • EVENT_ID
  • ADDRESS_ID

INVITATIONS

  • CONTACT_ID
  • EVENT_ID
  • RESPONDED

CONTACTS

  • CONTACT_ID

It's not a good idea to model a contact to be encompassing an entire family. It makes it easier to invite & track things if a contact represents a person rather than a household. After all, a household can have anywhere from 0 to ~18 kids, and may not include a significant other. Each person, assuming teens & up, will have unique contact info (IE: cell phone(s), work numbers, email, etc). This also makes it easier to determine headcount...

The invitations table allows you to summarize invitations & confirmations:

  SELECT e.event_name,
         SUM(invited.contact_id) 'total_invited',
         SUM(confirmed.contact_id) 'total_invitations_confirmed'
    FROM EVENT e
    JOIN INVITATIONS invited ON invited.event_id = e.event_id
    JOIN INVITATIONS confirmed ON confirmed.event_id = e.event_id
                            AND confirmed.responded = 'Y'
GROUP BY e.event_id, e.event_name

Just need to join to CONTACTS table to determine age and then be able to subcategorize the invitations between adults & children.

FAMILIAL_RELATIONS

  • CONTACT_ID
  • RELATED_CONTACT_ID
  • RELATION_TYPE (parent, child, aunt/uncle, cousin, blacksheep etc)

Use this table to rollup to get household members...


CONTACT_METHODS

  • CONTACT_ID
  • METHOD_TYPE (phone, cell, biz phone, fax, email, IM, etc)
  • METHOD_VALUE

CONTACT_ADDRESS_XREF

  • CONTACT_ID
  • ADDRESS_ID
  • ADDRESS_TYPE (home, business, etc)

ADDRESSES

  • ADDRESS_ID
  • ADDRESS_1
  • ADDRESS_2
  • ADDRESS_3
  • ADDRESS_4
  • CITY
  • PROV_STATE
  • POSTAL_CODE
  • COUNTRY

You'll notice I made a one to one relationship with EVENTS and ADDRESSES, while supporting one-to-many contact to addresses. Locations will be relatively static, compared to people. This format would allow you to easily check which event locations are popular, so you could use the information to get better rates in the future.

Regarding addresses for the same household: That's why the ADDRESSES is a separate table - you don't need to retype it for each person, just associate to the correct address record.

Do you need to track the indiviual invitations and responses?

If so you could have a separate table for Invitations and their statuses. Then you could obtain your counts from queries against that table.

If you are simply keeping a track of counts I might normalise to separate tables for InvitationCount with a discriminator column for Adult, Child or anything else. This avoids hard coding into your schema just two categories of invitation. Perhpas in the future you might have more categories (eg. Customers, Clients, Participants, Observers, Performers, Musicians, Donors, Honorary members ...)

[T]he contact right now is the whole family as one invitation is sent to one family

In that case, and absent any other requirements, I'd probably suggest a similar route to what you've already proposed.

The redundant fields aren't an issue, since they are tracking a unique fact about the Invitation, not the contact.

I'd probably keep a separate table for the Response (with number attending, which may be different from number invited) or an Attendee table, but it's not really necessary given your current requirements.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!