外键

发表于:2007-06-22来源:作者:点击数: 标签:

   

外键关系允许把一个数据表里的一个索引声明为另一数据表里的一个索引有关联关系,还允许对外键所在的数据表设置一些操作处理方面的约束条件。数据库根据外键关系定义的规则来维护引用完性。

MySqll里的外键支持是由InnoDB数据表处理程序提供的。

create table parent

(

par_id int not null,

parimary key(par_id)    

)type = innodb;

create table child

(

par_id int not null,

child_id int not null,

primary key(par_id,child_id),

foreign key(par_id) references parent(par_id) on delete cascade

) type = innodb;

自己参考用

原文转自:http://www.ltesting.net