将json数据存储在一个affiliate_phone_id
字段中或使用单独的表对其进行规范化更好?
例如:
mysql> select * from phone;
+----+----------+-------------+-------------------------------------------------------------------------------------------+
| id | name | description | affiliate_phone_id |
+----+----------+-------------+-------------------------------------------------------------------------------------------+
| 32 | iPhone 5 | faster CPU | [{"affiliate_id":2,"affiliate_phone_id":123},{"affiliate_id":3,"affiliate_phone_id":222}] |
+----+----------+-------------+-------------------------------------------------------------------------------------------+
上面的数据显示每个零售商都有自己的电话号码,例如:
公司 2 (affiliate_id = 2),他们的电话 ID 是 123
还是做这样的单独表格会更好:
mysql> select * from phone_affiliate;
+----+----------+--------------+--------------------+
| id | phone_id | affiliate_id | affiliate_phone_id |
+----+----------+--------------+--------------------+
| 1 | 32 | 2 | 123 |
| 2 | 32 | 3 | 222 |
+----+----------+--------------+--------------------+
还是有其他更好的建议?