private message database design

人走茶凉 提交于 2019-12-06 00:59:16

In this case, I'd vote for one table.

In general, whenever the data in two tables is the same or very similar and the logical concepts they represent are closely related, I'd put them in a single table. If there are lots of differences in the data or the concepts are really different, I'd make them two tables.

If you make two tables and you find yourself regularly writing queries that do a union of the two, that's an indication that they should be combined.

If you make one table but you find there are many fields that are always null for case A and other fields that are always null for case B, or if you're giving awkward double-meanings to fields, like "for type A this field is the zip code but for type B it's the product serial number", that's an indication they should be broken out.

Using a single table is the most advantageous.

It allows better message threading possibilities and it reduces duplication of effort, i.e. what happens when you want to add a column.

I would rather use the first one and include an additional field del_code to both tables. So, you'll be able to hide deleted messages and still have them in your database.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!