foo_bars is a many-2-many table with both columns pointing to foo.id I want foo_bars.[id1, id] to for a unique key How do I avoid same id being used in a foo_bars entry.
i.e. insert into foo_bars (2,2) - How do I avoid this?
mysql> create table foo (id int(11), name varchar(255));
Query OK, 0 rows affected (0.49 sec)
mysql> desc foo;
+-------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| name | varchar(255) | YES | | NULL | |
+-------+--------------+------+-----+---------+-------+
2 rows in set (0.00 sec)
mysql> create table foo_bars (id1 int(11), id int(11));
Query OK, 0 rows affected (0.34 sec)
mysql> desc foo_bars;
+-------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| id1 | int(11) | YES | | NULL | |
| id | int(11) | YES | | NULL | |
+-------+---------+------+-----+---------+-------+
2 rows in set (0.00 sec)