当前位置: 动力学知识库 > 问答 > 编程问答 >

sql - 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: http://dev.mysql.com/doc/refman/4.1/en/innodb-foreign-key-constraints.html

分享给朋友:
您可能感兴趣的文章:
随机阅读: