drop table if exists table1_table2,table1,table2; create table table1 (id binary(16) not null primary key, field1 varchar(50)); create table table2 (id binary(16) not null primary key, field2 varchar(50)); create table table1_table2 (table1_id binary(16) not null, table2_id binary(16) not null, foreign key (table1_id) references table1(id), foreign key (table2_id) references table2(id)); insert into table2 (id, field2) values ('test','test'); insert into table1 (id, field1) values (_binary'test', 'field1value'); insert into table1_table2 (table1_id, table2_id) values (_binary'test', _binary'test'); delete from table1_table2 where table1_id = _binary'test'; delete from table1 where id = _binary'test'; mysql> drop table if exists table1_table2,table1,table2; Query OK, 0 rows affected, 3 warnings (0.00 sec) mysql> create table table1 (id binary(16) not null primary key, field1 varchar(50)); Query OK, 0 rows affected (0.10 sec) mysql> create table table2 (id binary(16) not null primary key, field2 varchar(50)); Query OK, 0 rows affected (0.10 sec) mysql> create table table1_table2 (table1_id binary(16) not null, table2_id binary(16) not null, -> foreign key (table1_id) references table1(id), -> foreign key (table2_id) references table2(id)); Query OK, 0 rows affected (0.15 sec) mysql> mysql> insert into table2 (id, field2) values ('test','test'); Query OK, 1 row affected (0.03 sec) mysql> insert into table1 (id, field1) values (_binary'test', 'field1value'); insert into table1_table2 (table1_id, table2_id) values (_binary'test', _binary'test'); Query OK, 1 row affected (0.03 sec) Query OK, 1 row affected (0.03 sec) mysql> delete from table1_table2 where table1_id = _binary'test'; delete from table1 where id = _binary'test'; Query OK, 0 rows affected (0.00 sec) Query OK, 0 rows affected (0.00 sec) mysql> select version(); +---------------------------------------+ | version() | +---------------------------------------+ | 5.5.28-enterprise-commercial-advanced | +---------------------------------------+ 1 row in set (0.00 sec)