C表为什么不是
aid, bid, ccontent
1, abc, 内容c
关联更简单, C.aid = A.aid;
在(aid, bid)上建了唯一索引 也可以replace into
索引也更加灵活, a, b, (a,b), (b,a)上皆可建索引, 具体看你的需求
更新
联合唯一索引:
mysql> create table a1 (a int, b int, unique key (a,b));
Query OK, 0 rows affected (0.13 sec)
mysql> show create table a1;
+-------+------------------------------------------------------------------------------
-----------------------------------------------------------------+
| Table | Create Table
|
+-------+------------------------------------------------------------------------------
-----------------------------------------------------------------+
| a1 | CREATE TABLE `a1` (
`a` int(11) DEFAULT NULL,
`b` int(11) DEFAULT NULL,
UNIQUE KEY `a` (`a`,`b`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
+-------+------------------------------------------------------------------------------
-----------------------------------------------------------------+
1 row in set (0.02 sec)
更新: replace into
mysql> delete from a1;
Query OK, 1 row affected (0.04 sec)
mysql> replace into a1 values(1,1, 1);
Query OK, 1 row affected (0.00 sec)
mysql> select * from a1;
+------+------+------+
| a | b | c |
+------+------+------+
| 1 | 1 | 1 |
+------+------+------+
1 row in set (0.00 sec)
mysql> replace into a1 values(1,1, 2);
Query OK, 2 rows affected (0.02 sec)
mysql> select * from a1;
+------+------+------+
| a | b | c |
+------+------+------+
| 1 | 1 | 2 |
+------+------+------+
1 row in set (0.00 sec)