Itay Moav -Malimovka Itay Moav -Malimovka - 14 days ago 4x
MySQL Question

MySql foreign key which is a composite key - what is the syntax?

Is it possible to have a composite key in mysql(5.1) and if so, what is the syntax?

table a:

column aa,bb

references table b

columns b_aa,b_bb


With InnoDB tables, you can, like:

create table YourTable (
     col1 int, 
     col2 int, 
     constraint foreign key (col1, col2) 
                references OtherTable (col1, col2) 
                on delete cascade
) type=InnoDB;

For MyISAM tables, foreign key constraint are silently ignored.

for complete tutorial: