Search code examples
mysqldatabasetypesentity-relationship

Modeling database with 2 type of users (web and twitter)


I have two types of users on the database: -Web registered users -Twitter users

I have to store data of both: - Web registered users: id, nick, mail, verified, password - Twitter users: id, nick

Currently i have just 2 tables: - webUsers: id, nick, mail, verified, password - twitterUsers: id, nick

But it carry some problems for example with the comments table. Both users can make comments so i would need two foreigns key and that's not possible.

I also thought about this possibility: - users: id, nick - users_twitter: id, - users_web: id, nick, mail, verified, password.

It would represent the main table users with two childrens: users_twitter and users_web. But... the table users_twitter has only one field: id isn't that weird?

What would you recommend me? OH, by the way. Twitter users id is the one i get from twitter API, so it might be possible that ID could be same of my of the web users ID.

Thanks.


Solution

  • So, you've a hierarchy there. You have some common fields that could be part of a Users table and some others that should be part of each of the childrens: UsersTwitter and UsersWeb. You can take a look at this post to see how to handle hierarchies.