开发者

Multiple Database Associative Entity

开发者 https://www.devze.com 2023-03-25 02:04 出处:网络
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 man

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

精彩评论

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