简体   繁体   中英

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?

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM