开发者

Multiple Database Associative Entity

Quick question about database design.

If I have two databases:开发者_如何学C User_DB and Group_DB, and User_DB contain a table named User_TB and Group_DB contain a table named Group_TB. This is a many to many relationship so User can belong to many Groups and a Group can have many Users. So there is an associative entity between them UserGroup. Where should this table be placed? In the User_DB or Group_DB?


Assuming there is a valid reason for having two separate databases, I would be inclined towards keeping it in the database that 'owns' the relationship - the answer would differ based upon how the entities and relationships are defined in the problem domain, and probably would be subjective.

In this case Users belongs to Groups - this relationship is leaning heavily towards users instead of Groups and hence I would be inclined to keep the mapping in User_DB.


Most RDBMS do not support cross-database foreign keys.

Your's may, but keep in mind that at a given time one database may be down for maintenance, or not available, or under heavy load ..etc. So, having cross-db foreign keys may not be a good idea even if you can do it.

Therefore, I would suggest to keep both tables in the same DB.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜