Sebastian Zeki
Sebastian Zeki

Reputation: 6874

Can I have a table with two foreign keys?

I am creating a social media site. Users can create a category (1 user to many categories) and each category has many entries. I want to allow users to post on events (1 event can have many posts).

In other words the event owns the post but I want to be able to identify the user who created that post.

Does this mean that I should create 1 event to many posts as well as 1 user to many posts? Does this create normalization problems. What's the best way around this?

Upvotes: 0

Views: 71

Answers (1)

Juan Carlos Oropeza
Juan Carlos Oropeza

Reputation: 48177

I dont see any relation between category and events
In that case add a categoryID as FK in Events

  • Users table

    1. userID Primary key
  • Categories table

    1. categoryID Primary key
    2. userID Foreign Key (users)
  • Events

    1. eventID Primary key
  • Posts

    1. postID Primary key
    2. eventID Foreign Key (events)
    3. userID Foreign Key (users)

Upvotes: 2

Related Questions